jQuery實現(xiàn)的鼠標響應緩沖動畫效果示例
更新時間:2018年02月13日 12:22:05 作者:lexie
這篇文章主要介紹了jQuery實現(xiàn)的鼠標響應緩沖動畫效果,涉及jQuery事件響應、數(shù)值運算及頁面元素動態(tài)操作相關技巧,需要的朋友可以參考下
本文實例講述了jQuery實現(xiàn)的鼠標響應緩沖動畫效果。分享給大家供大家參考,具體如下:
先來看看運行效果:

具體代碼如下:
<!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>
更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》、《jQuery拖拽特效與技巧總結》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
jQuery實現(xiàn)帶右側(cè)索引功能的通訊錄示例【附源碼下載】
這篇文章主要介紹了jQuery實現(xiàn)帶右側(cè)索引功能的通訊錄,結合實例形式分析了jQuery針對頁面元素動態(tài)遍歷、排序等相關操作技巧,并附源碼供讀者下載參考,需要的朋友可以參考下2018-04-04
jQuery+jqmodal彈出窗口實現(xiàn)代碼分明
jQuery+jqmodal彈出窗口的制作方法,需要的朋友可以參考下。2010-06-06

