【发布时间】:2014-10-14 02:06:08
【问题描述】:
/**Script**/
function AnimateFish() {
var Fish3 = $("#fish1").not(".HoverFish"),
theContainer = $("#container"),
maxLeft = theContainer.width() - Fish3.width() - 50,
maxTop = theContainer.height() - Fish3.height(),
leftPos = Math.floor(Math.random() * maxLeft),
topPos = Math.floor(Math.random() * maxTop) + 100,
imgRight = "Assets/fish-glow3-right.gif",
imgLeft = "Assets/fish-glow3.gif";
if (Fish3.position().left <= leftPos) {
$(this).css("background-image", 'url("' + imgRight + '")');
} else {
$(this).css("background-image", 'url("' + imgLeft + '")');
}
Fish3.animate({
"left": leftPos,
"top": topPos
}, 1800, AnimateFish);
}
AnimateFish();
您好,id "#fish1" 将像 #fish1、#fish2 #fish3 一样动态生成...实际上我希望应该为所有生成的 id 运行此函数,请给我解决方案和一个主要问题鱼我尝试了很多此代码是否会反转,请 PPL 帮助我...
【问题讨论】:
-
使用选择器来执行此操作。 stackoverflow.com/questions/5002966/…
-
而且这个网站通常不会很好地回应“给我解决方案”。除了我认为的问题之外,您的问题还很完善。欢迎加入社区
-
他没有说“给我解决方案”,他只是想要解决方案。
标签: javascript jquery