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

更新於: 10-12-2019

202 次訪問

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告