【发布时间】:2014-03-10 10:42:38
【问题描述】:
其实我是 JavaScript 的初学者,我需要一个 JavaScript 功能的要求。 每当我将鼠标悬停在我的徽标上时,该徽标都应该移到身体上。这意味着当我将鼠标光标放在徽标上时,它应该离开该位置并移动到其他位置。
我正在尝试,但代码对我不起作用。任何人都可以在这方面建议我。作为参考,我将下面的链接粘贴为 gif 图像。
<script type="javascript">
$("#logo").mouseover(function(){
if(!logoMove){return;}
var tmp=new Array(
{left:10, top:10},
{left:10, top:$("#bodycontainer").height()-220},
{left:$("#bodycontainer").width()-220, top:$("#bodycontainer").height()-220},
{left:$("#bodycontainer").width()/2, top:$("#bodycontainer").height()/2},
{left:$("#bodycontainer").width()-220, top:20}
);
var rand = Math.floor(Math.random() * tmp.length);
while(tmp[rand].left == $(this).css("left") &&
tmp[rand].top == $(this).css("top")){
rand = Math.floor(Math.random() * tmp.length);
}
$(this).stop().animate({
left:tmp[rand].left,
top:tmp[rand].top
},
400
);
});
}
<script>
<div id="logo">
<img width="500" height="462" src="http://www.gameark.com/templates/onarcade/images/logo.png" >
</div>
参考点击link.
【问题讨论】:
-
这是我找到的一个帖子。尝试这个。 stackoverflow.com/questions/11929687/…
标签: javascript jquery html css