如何使用緩動效果執行 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.com/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