我用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>
解决方案 »
- JS 正则表达式匹配"0001-9999","001-999","01-99"
- 请教如何屏蔽掉iframe里的网页的js?
- 如何动态获取 table 中 td 所在行 和列
- 跳转页时传递多个参数的问题!!!!
- 在JavaScript中,如何判断一个返回值是不是对象?
- 那里有javaScript的初级教程?
- 滚动条的不稳定因素
- [高分求救]如何判断这个表单里有多少个字段要作答和每个字段是否都已经做答了(也就是值不为空),在线等待!
- 问一个关于JSCRIPT的菜问题。。。
- 第一个页面中有3个iframe页面,在iframe的页面中包含cba的A标签,在点击cba这个标签的时候,动态在包含cba这个a标签的页面添加div
- 这段代码 哪里错了 求指教
- 还是this的问题?
<!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
嗯嗯, 我用的方法可以了。
后面我又发现用postion:absolute;这个也可以,用这要把position:relative;设置在d_zong里,不然是默认body所以不可以的吧。
嘿嘿,完美解决 谢谢啦。