欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery插件實(shí)現(xiàn)無(wú)縫輪播

 更新時(shí)間:2021年05月07日 07:58:25   作者:阿飛超努力  
這篇文章主要為大家詳細(xì)介紹了jquery插件說(shuō)下無(wú)縫輪播,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

無(wú)縫輪播是一個(gè)很常見(jiàn)的效果,理解邏輯之后就很簡(jiǎn)單了。

效果如下

代碼部分

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>做無(wú)縫輪播</title>
  <script src="js/jquery-3.4.1.min.js"></script>
  <style>
   * {
    margin: 0;
    padding: 0;
    user-select: none;
   }

   #div {
    border: 1px solid lightgray;
    width: 600px;
    height: 300px;
    margin: 20px;
    overflow: hidden;
   }
   .item {
    border: 1px solid lightgray;
    width: 96%;
    height: 50px;
    margin: 10px auto;
   }
  </style>
 </head>
 <body>
  <div id="div">
   <div class="rollbox"></div>
  </div>
 </body>
</html>
<script>
 $(document).ready(function() {
  for (var i = 0; i < 7; i++) {
   var $item = $("<div class='item'>" + i+ "</div>");
   $item.appendTo($("#div .rollbox"));
  }
 })
 //輪播動(dòng)作

 $(function() {
  $("#div").roll(1);
 })

 $.prototype.roll = function(span) {
  span = span == undefined ? 20 : span; //滾動(dòng)速率
  var $that = $(this).find('.rollbox');
  var index = 0;
  var t = setInterval(function() {
   $that.css('margin-top', index + 'px');
   index--;
   check();
  }, span)
  //
  $that.mouseenter(function() {
   clearInterval(t);
  })
  $that.mouseleave(function() {
   t = setInterval(function() {
    $that.css('margin-top', index + 'px');
    index--;
    check();
   }, span)
  })
  function check(){
   var first = $that.children().first();
   var top = parseInt(first.css('margin-top').replace('px',''));
   var bottom = parseInt(first.css('margin-bottom').replace('px',''));
   var height  =first.height();
   bw = parseInt(first.css('border-width').replace('px',''));
   var temp = index+top+height+bottom;
   if(temp==top-2*bw){
    var last = $that.children().last();
    last.after(first);
    $that.css('margin-top','0px');
    index=0;
   }
  }
 }
</script>

思路解釋

  • 一開(kāi)始我是打算直接在元素上面進(jìn)行動(dòng)畫效果的,不過(guò)中間彎彎繞繞還是有點(diǎn)煩,所以直接給一個(gè)輔助容器,包住所有子元素,我們讓這個(gè)輔助容器上下運(yùn)動(dòng)就行
  • 就是你緩慢移動(dòng)輔助容器往上的時(shí)候,就已經(jīng)有滾動(dòng)效果了,然后我們判斷最上面的那個(gè)容器是否已經(jīng)完全隱去,然后再把輔助容器復(fù)位,把最上面額元素放到最下面就行了

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論