animate語法: 
復制代碼 代碼如下:
 
$(selector).animate(styles,speed,easing,callback) 
復制代碼 代碼如下:
 
<!doctype html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Testing</title> 
<link href="css/reset.css"> 
<script src="js/jquery.js"></script> 
<style> 
.wrap { 
position: relative; 
height: 300px; 
width: 300px; 
border:5px solid #FCF; 
} 
.wrap div { 
position: absolute; 
left: 0;top: 0; 
height: 50px; 
width: 50px; 
background: #FA0; 
} 
</style> 
</head> 
<body> 
<input type="button" value="停止當前動畫"> 
<input type="button" value="停止所有動畫"> 
<input type="button" value="停止所有動畫,到達終點"> 
<div> 
<div></div> 
</div> 
<script> 
function moveX(){ 
$('.wrap div').animate({'left':'250px'},1000).animate({'left':'0px'},1000); 
} moveX(); 
$('#btn1').click(function(){ 
$('.wrap div').stop(); // 停止當前動畫,沿路返回起點,若是返回過程中再點擊,會暫停在路中 
clearInterval(); 
}) 
$('#btn2').click(function(){ 
$('.wrap div').stop(true); // 停止所有動畫 去的路程中點擊停止會直接到達終點,若是返回過程中再點擊,會暫停在路中 
}) 
$('#btn3').click(function(){ 
$('.wrap div').stop(true,true); // 停止所有動畫 ,去的路程中點擊停止會直接到達終點,若是返回過程中再點擊,會停止到在起點 
}) 
// .stop() // 停止當前動畫 
// .stop(true) // 停止所有動畫 
// .stop(true,true) // 停止所有動畫,到達動畫終點 
</script> 
</body> 
</html> 
新聞熱點
疑難解答
圖片精選