jQuery實現(xiàn)的鼠標(biāo)響應(yīng)緩沖動畫效果示例
本文實例講述了jQuery實現(xiàn)的鼠標(biāo)響應(yīng)緩沖動畫效果。分享給大家供大家參考,具體如下:
先來看看運行效果:

具體代碼如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>js動畫-緩沖動畫</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.js"></script>
<style>
* {
margin: 0;
padding: 0;
font-family:"微軟雅黑"
}
#box{
height:100px;
width:100px;
background-color:#0099CC;
margin-top:200px;
position:relative;
/*速速、緩沖變化*/
left:-100px;
}
span{
display:block;
color:blue;
width:25px;
height:100px;
background-color:#FFFF99;
position:absolute;
left:100px;
}
</style>
</head>
<body>
<div id="box">
<span>移動</span>
</div>
<script>
window.onload=function(){
var div1=document.getElementById("box");
div1.onmouseover=function(){
startMove(0);
}
div1.onmouseout=function(){
startMove(-100);
}
}
var timer=null;
function startMove(itarget){
clearInterval(timer);
var div1=document.getElementById("box");
timer=setInterval(function(){
var speed=(itarget-div1.offsetLeft)/20;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(div1.offsetLeft==itarget){
clearInterval(timer);
}else{
div1.style.left=div1.offsetLeft+speed+"px";
}
},30)
}
</script>
</body>
</html>
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
jQuery實現(xiàn)帶右側(cè)索引功能的通訊錄示例【附源碼下載】
這篇文章主要介紹了jQuery實現(xiàn)帶右側(cè)索引功能的通訊錄,結(jié)合實例形式分析了jQuery針對頁面元素動態(tài)遍歷、排序等相關(guān)操作技巧,并附源碼供讀者下載參考,需要的朋友可以參考下2018-04-04
jQuery+jqmodal彈出窗口實現(xiàn)代碼分明
jQuery+jqmodal彈出窗口的制作方法,需要的朋友可以參考下。2010-06-06
jquery實現(xiàn)美觀的導(dǎo)航菜單鼠標(biāo)提示特效代碼
這篇文章主要介紹了jquery實現(xiàn)美觀的導(dǎo)航菜單鼠標(biāo)提示特效代碼,涉及jquery鼠標(biāo)事件及頁面animate動畫的使用技巧,非常具有實用價值,需要的朋友可以參考下2015-09-09

