JQ自定义运动问题?初级

haorenge haorenge 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<!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" />
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<title>Examples</title>
<style type="text/css">
*{padding: 0;margin: 0;}
li{list-style: none;}
#box{
width: 410px;
height: 320px;
margin: 30px auto;
}
#box li{
width: 180px;
height: 160px;
overflow: hidden;
border: 1px solid red;
float: left;
margin: 5px;
position: relative;
}
#box li div{
position: absolute;
top: 0;
left: 0;
}

</style>
</head>
<body>
<script type="text/javascript">
$(function(){
setInterval(function(){
var num=Math.random()>0.5?160:-160;
var num2=Math.floor(Math.random()*3);
var ThisTop=$('#box ul li div').eq(num2).position().top;
if(ThisTop==0){
$('#box ul li div').eq(num2).stop().animate({'top':'-=160px'}, 300)
}else if(ThisTop==-320){
$('#box ul li div').eq(num2).stop().animate({'top':'+=160px'}, 300)
}else{
$('#box ul li div').eq(num2).stop().animate({'top':'+='+num}, 300)
}
//我想要的方法
//$('#box ul li div').eq(num2).animate('top':function(){
// if(){return ...} 为什么不行?还是我的格式有问题
// })




},1500)




})
</script>
<div id="box">
<ul>
<li>
<div>
<img src="images/001.gif" alt="" />
<img src="images/002.gif" alt="" />
<img src="images/003.gif" alt="" />
</div>
</li>
<li>
<div>
<img src="images/004.gif" alt="" />
<img src="images/005.gif" alt="" />
<img src="images/006.gif" alt="" />
</div>
</li>
<li>
<div>
<img src="images/007.gif" alt="" />
<img src="images/008.gif" alt="" />
<img src="images/009.gif" alt="" />
</div>
</li>
</ul>
</div>
</body>
</html>


刚学JQ不久 求指导.
...全文
评论 6
收藏 已收藏
分享
返回顶部
haorenge
JavaScript 87,983 成员 224,681 内容