要实现jQuery ScrollLeft,请使用jQuery Easing插件。缓动插件用于动画。
您需要首先添加Easing Plugin库。让我们添加CDN:
script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.compatibility.min.js"></script>
您可以尝试运行以下代码以轻松实现jQuery ScrollLeft:
<!DOCTYPE html> <html> <head> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.compatibility.min.js"></script> <script> $(document).ready(function() { $("#button1").click(function() { jQuery.easing.def = 'easeOutBounce'; $('#test').animate({"margin-left": '100'}, 'slow'); }); }); </script> <style> #test { width:150px; height:150px; background-color:#6C220A; } </style> </head> <body> <div id="test"></div> <button id="button1">Scroll</button> </body> </html>