• Django打造大型企业官网(六)


    4.9.根据轮播图个数修改小圆点数量

    src/js/index.js

    function Banner() {
        this.bannerWidth = 798;
    }
    
    Banner.prototype.initBanner = function () {
        var self = this;
        this.bannerUL.css({
            "width":self.bannerWidth*self.bannerCount
        })
    };
    
    Banner.prototype.initPageControl = function () {
      var self = this;
      var pageControl = $(".page-control");
      for (var i=0;i<self.bannerCount;i++){
          var circle = $("<li></li>");
          pageControl.append(circle);
          if (i === 0){
              circle.addClass("active");
          }
      }
      pageControl.css({"width":self.bannerCount*12+8*2+16*(self.bannerCount-1)});
    };
    
    Banner.prototype.run = function () {
        this.initBanner();
        this.initPageControl();
        this.loop();
        this.listenArrowClick();
    };

    4.10.小圆点点击事件和自动更新当前选中的小圆点

    src/js/index.js

    function Banner() {
            this.pageControl = $(".page-control");
    };
    
    Banner.prototype.animate = function () {
        var self = this;
        self.bannerUL.animate({"left":-798*self.index},500);
        // 通过index获取到当前的li标签,添加active样式,兄弟li标签移除active样式
        self.pageControl.children('li').eq(self.index).addClass("active").siblings().removeClass("active");
    };
    
    Banner.prototype.listenPageControl = function () {
        var self = this;
        self.pageControl.children("li").each(function (index,obj) {
            $(obj).click(function () {
                self.index = index;
                self.animate();
            });
        });
    };
    
    Banner.prototype.run = function () {
        this.listenBannerHover();
    };

    src/css/scss.css

    .header{
         z-index: 100;
    
    
    
    .banner-group{
    
        overflow:hidden;
        z-index: 0;

    4.11.实现自动循环无限轮播

    src/js/index.js

    function Banner() {
        this.index = 1;
    };
    
    Banner.prototype.initBanner = function () {
        var self = this;
        //实现无限轮播,原理:123-->>31231,在首尾克隆一张
        var firstBanner = self.liList.eq(0).clone();
        var lastBanner = self.liList.eq(self.bannerCount-1).clone();
        self.bannerUL.append(firstBanner);
        self.bannerUL.prepend(lastBanner);
        self.bannerUL.css({
            "width":self.bannerWidth*(self.bannerCount+2),
            "left":-self.bannerWidth,
        });
    };
    
    Banner.prototype.animate = function () {
        var self = this;
        self.bannerUL.animate({"left":-798*self.index},500);
        //小圆点的active
        var index = self.index;
        if(index === 0){
            index = self.bannerCount-1;
        }else if(index === self.bannerCount+1){
            index = 0;
        }else{
            index = self.index - 1;
        }
        // 通过index获取到当前的li标签,添加active样式,兄弟li标签移除active样式
        self.pageControl.children('li').eq(index).addClass("active").siblings().removeClass("active");
    };
    
    Banner.prototype.loop = function(){
        var self = this;
        this.timer = setInterval(function () {
            if(self.index >= self.bannerCount+1){
                self.bannerUL.css({
                    "left":-self.bannerWidth,
                });
                self.index = 2;
            }else{
                self.index++;
            }
            self.animate();
        },2000);
    };

    4.12.左右牵头切换实现循环轮播

    src/js/index.js

    Banner.prototype.listenArrowClick = function () {
        var self = this;
        self.leftArrow.click(function () {
           if(self.index === 0){
               self.bannerUL.css({
                  "left":-self.bannerCount*self.bannerWidth,
               });
               self.index = self.bannerCount - 1;
           }else{
               self.index --;
           }
           self.animate();
        });
    
        self.rightArrow.click(function () {
           if(self.index === self.bannerCount + 1){
               self.bannerUL.css({
                  "left":-self.bannerWidth,
               });
               self.index = 2;
           }else{
               self.index ++;
           }
           self.animate();
        });
    };
  • 相关阅读:
    在GitHub上删除项目后,在Android Studio上传项目依然提示project is already on github
    Android Studio 使用Intent实现页面的跳转(带参数)
    Android Studio 点击两次返回键,退出APP
    Android Studio 使用ViewPager + Fragment实现滑动菜单Tab效果 --简易版
    Eclipse 分屏显示同一个代码文件
    关于线上问题处理心得分享
    关于敏捷开发
    Python语言程序设计学习 之 了解Python
    关于测试
    C# 使用FileUpload控件上传图片,将文件转换成二进制进行存储与读取
  • 原文地址:https://www.cnblogs.com/derek1184405959/p/11067993.html
Copyright © 2020-2023  润新知