Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách tắt toàn bộ animation bằng jQuery


Để tắt toàn bộ animation bằng jQuery, dùng phương thức jQuery.fx.off.

Để bật animation:

$("#enable").click(function(){    jQuery.fx.off = false; });

Để tắt animation, đặt jQuery.fx.off = true:

$("#disable").click(function(){    jQuery.fx.off = true; });

Ví dụ minh họa:

Ví dụ

<html> <head> <title>Ví dụ jQuery</title>    <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>    <script language = "javascript">       $(document).ready(function() {          $("#enable").click(function(){             jQuery.fx.off = false;          });          $("#disable").click(function(){             jQuery.fx.off = true;          });          $("#go").click(function(){             $(".target").animate({left: '+=200px'}, 2000);          });          $("#back").click(function(){             $(".target").animate({left: '-=200px'}, 200);          });          });    </script> <style> p {background-color:#bca; width:350px; border:1px solid green;} div{position: absolute; left: 50px; top:300px;} </style> </head> <body> <p>Nhấn Bật hoặc Tắt rồi nhấn GO hoặc BACK:</p> <button id = "enable"> Bật</button> <button id = "disable"> Tắt </button> <button id = "go"> GO</button> <button id = "back"> BACK </button> <div class = "target">    <img src = "./images/jquery.jpg" alt = "jQuery" /> </div> </body> </html>