jQuery 停止动画 stop()

来源:互联网 发布:linux ifconfig 找不到 编辑:程序博客网 时间:2024/06/05 05:47

stop():停止匹配的元素上当前运行的动画。

<!doctype html><html lang="en"><head>  <meta charset="utf-8">  <title>stop demo</title>  <style>  div {    position: absolute;    background-color: #abc;    left: 0px;    top: 30px;    width: 60px;    height: 60px;    margin: 5px;  }  </style>  <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><button id="go">Go</button><button id="stop">STOP!</button><button id="back">Back</button><div class="block"></div><script>// Start animation$( "#go" ).click(function() {  $( ".block" ).animate({ left: "+=100px" }, 2000 );});// Stop animation when button is clicked$( "#stop" ).click(function() {  $( ".block" ).stop();});// Start animation in the opposite direction$( "#back" ).click(function() {  $( ".block" ).animate({ left: "-=100px" }, 2000 );});</script></body></html>
原创粉丝点击