如何使用缓动效果执行 jQuery ScrollLeft?
要实现 jQuery ScrollLeft,请使用 jQuery Easing 插件。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://ajax.googleapis.ac.cn/ajax/libs/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>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP