我用jquery里的animate方法写个移动,在移动超出div的时候使超出隐藏起来要怎么写,写个可以滚动的广告那样的,当超出div的时候能把图片隐藏起来。属性好像是用overflow: hidden;怎么用也没用,代码写的有点乱,希望有人帮忙。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="jquery-1.4.min.js"></script>
<script type="text/jscript">
$(document).ready(function(){
$("#d1").click(function(){
$("#d11").slideToggle("slow");
});   
$("#d2").click(function(){
$("#d22").slideToggle("slow");
});

$("#d3").click(function(){
$("#d33").slideToggle("slow");
});

$("#d4").click(function(){
$("#d44").slideToggle("slow");
});
  
$(".d_left").click(function(){
// alert("0");

$(".d_test").animate({left: '-=50px'}, "slow");

});   $(".d_right").click(function(){
// alert("0");

$(".d_test").animate({left: '+=50px'}, "slow");

});
});
</script><style>
*{ margin:0px; padding:0px;}.d1{
width:400px;
height:30px;
border:1px #999 solid;
background:#CCC;
text-align:center; }
.d2{

height:500px;
border:1px #999 solid;
background-image:url(1.jpg);
clear:both;
display:none;
}

.d3_1{
margin-top:10px;
width:100px;
height:180px;
border:1px #999 solid;
float:left;
}
.d_test{
position:absolute;
background:#06F
}
.d_zong{
width:700px;
height:140px;
border:1px #333 solid;
overflow:hidden;
}
.d_li{
position:absolute
overflow: hidden;
width:600px;
height:140px;
border:1px #333 solid;
}
.d_left{ width:30px; height:140px; float:left; background:#999; }
.d_right{ width:30px; height:140px; background:#999; float:right;float:left; }
</style>
</head><body><hr />
<div>
<div class="d_left"><<</div><div class="d_zong">
<div class="d_li">
<div class="d_test"  style="width:100px; height:100px;  margin:20px; left:120px;">aaaa</div>
<div class="d_test"  style="width:100px; height:100px;  margin:20px; left:240px;">bbbbb</div>
<div class="d_test"  style="width:100px; height:100px;  margin:20px;left:360px;">cccccc</div>
<div class="d_test"  style="width:100px; height:100px; margin:20px; left:480px;">dddd</div>
</div>
</div><div class="d_right">>></div>
</div>
</body>
</html>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://www.wanmei.com/public/js/jq_132.js"></script>
    <script type="text/jscript">
    $(document).ready(function(){
    $("#d1").click(function(){
    $("#d11").slideToggle("slow");
    });  
    $("#d2").click(function(){
    $("#d22").slideToggle("slow");
    });$("#d3").click(function(){
    $("#d33").slideToggle("slow");
    });$("#d4").click(function(){
    $("#d44").slideToggle("slow");
    });
     
    $(".d_left").click(function(){
    // alert("0");$(".dd").animate({marginLeft: '-=10px'}, "slow");});  $(".d_right").click(function(){
    // alert("0");$(".dd").animate({marginLeft: '+=10px'}, "slow");});
    });
    </script><style>
    *{ margin:0px; padding:0px;}.d1{
    width:400px;
    height:30px;
    border:1px #999 solid;
    background:#CCC;
    text-align:center;}
    .d2{height:500px;
    border:1px #999 solid;
    background-image:url(1.jpg);
    clear:both;
    display:none;
    }.d3_1{
    margin-top:10px;
    width:100px;
    height:180px;
    border:1px #999 solid;
    float:left;
    }
    .d_test{
    background:#06F;
    float:left;
    }
    .d_zong{
    width:700px;
    height:140px;
    border:1px #333 solid;
    overflow:hidden;
    }
    .d_li{overflow: hidden;
    width:600px;
    height:140px;
    border:1px #333 solid;
    }
    .d_left{ width:30px; height:140px; float:left; background:#999; }
    .d_right{ width:30px; height:140px; background:#999; float:right;float:left; }
    </style>
    </head><body><hr />
    <div>
    <div class="d_left"><<</div><div class="d_zong">
    <div class="d_li">
    <div class="dd" style="margin-left:20px;">
    <div class="d_test" style="width:100px; height:100px; margin-left:0px;">aaaa</div>
    <div class="d_test" style="width:100px; height:100px; margin-left:40px;">bbbbb</div>
    <div class="d_test" style="width:100px; height:100px; margin-left:40px;">cccccc</div>
    <div class="d_test" style="width:100px; height:100px; margin-left:40px;">dddd</div>
    </div>
    </div>
    </div><div class="d_right">>></div>
    </div>
    </body>
    </html>
    别用postion:absolute;
    这样就脱离文本流了用margin-left
      

  2.   


    嗯嗯, 我用的方法可以了。
       后面我又发现用postion:absolute;这个也可以,用这要把position:relative;设置在d_zong里,不然是默认body所以不可以的吧。   
    嘿嘿,完美解决  谢谢啦。