其實我是JavaScript的初學者,我需要JavaScript功能的一項要求。 每當我將鼠標放在我的標誌上時,該標誌應該移動到身體上。這意味着當我將鼠標光標放在徽標上時,應該離開該位置並移動到其他位置。Javascript logo移動鼠標懸停功能
我在嘗試,但代碼不適合我。任何人都可以在這方面提出建議。作爲參考,我粘貼下面的鏈接爲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.
看看這一個http://stackoverflow.com/questions/7031701/moving-an-image-10px-on-hover-and-changing-opacity – Pavlo
這裏是我發現的一篇文章。嘗試這個。 http://stackoverflow.com/questions/11929687/tricky-button-moving-away-when-mouseover-in-javascriptl – CodeMonkey