zoukankan      html  css  js  c++  java
  • 页面轮播

    (function($){
        $.extend($.fn, {
            slide: function(){
                this.each(function() {
                    var $self = $(this);
                    var dom = {
                      "wrap": $self.find(".bannerlist"),
                      "item": $self.find(".bannerlist li"),
                      "firstItem": $self.find(".bannerlist li").first(),
                      "lastItem": $self.find(".bannerlist li").last(),
                      "pagelist": null,
                      "pageItem": null,
                    }
                    var settings = {
                      "len": dom.item.length,
                      "auto":  true,
                      "timer" : null,
                      "index" : 1,
                      "time"  : 3000
                    };
                    var funs = {
                      init: function() {
                        if (settings.len < 2) return;
                          var cloneFisrt = dom.firstItem.clone();
                          var cloneLast = dom.lastItem.clone();
                          dom.wrap.append(cloneFisrt);
                          cloneLast.insertBefore(dom.firstItem);
    
                          var page = '<ul class="banner_bar">';
                          for (var i = 0; i < settings.len; i++) {
                              if (i == 0) {
                                page += '<li class="active"></li>';
                              } else {
                                page += '<li></li>';
                              }
                           }
                          page += '</ul>';
                          $self.append(page);
                          dom.pagelist = $self.find(".banner_bar");
                          dom.pageItem = dom.pagelist.find("li");
    
                          dom.item = $self.find(".bannerlist li");
                          settings.count = dom.item.length;
    
                          dom.wrap.css("transform", "translateX(-100%)");
    
                          this.Event();
    
                          if(settings.auto){
                            settings.timer = setInterval(this.Animate, settings.time);
                          }
                      },
                      Event: function(){
                          var that = this;
                          $self.on('click','.banner_bar li',function(){
                            settings.index = $(this).index() + 1;
                            dom.wrap.addClass("transform");
                            dom.wrap.css("transform", "translateX(" + -settings.index * 100 + "%)");
                          }).on('mouseenter','.banner_bar li',function(){
                            clearInterval(settings.timer)
                          }).on('mouseleave','.banner_bar li',function(){console.log('leave')
                            settings.timer = setInterval(that.Animate, settings.time);
                          }).on('webkitTransitionEnd','.bannerlist',function(){
                             dom.wrap.removeClass("transform");
                             if (settings.index <= 0) {
                                settings.index = settings.count - 2;
                              }
                              if (settings.index >= settings.count - 1) {
                                settings.index = 1;
                              }
                              var itemIndex =  settings.index - 1;console.log(itemIndex)
                              dom.pageItem.removeClass("active");
                              dom.pageItem.eq("" + itemIndex + "").addClass("active");
                              dom.wrap.css("transform", "translateX(" + -settings.index * 100 + "%)");
                          })
                      },
                      Animate: function(){
                            settings.index++;
                            dom.wrap.addClass("transform");
                            dom.wrap.css("transform", "translateX(" + -settings.index * 100 + "%)");
                      }
                    }
                    funs.init();
                })
            }
        })
    })(window.jQuery)
    

      

  • 相关阅读:
    UML统一建模语言笔记
    从零开始学JavaWeb
    也谈微信小程序
    Memcached,你懂的
    一个简单的配置管理器(SettingManager)
    我的AngularJS 学习之旅
    .NET Core 跨平台
    ASP.NET Core 中间件自定义全局异常处理
    面试必考题——递归解题套路
    程序员着装指南
  • 原文地址:https://www.cnblogs.com/tianwengao/p/6961271.html
Copyright © 2011-2022 走看看