Slideshow.js 4.5 KB
//*
// 图片轮播
// */

import Loger from "../Loger";
import Ape from "./Ape";
import xdysdk from "libs/xdysdk";
import DrawTool from "./DrawTool";
import LaserPen from "./LaserPen";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";

let loger = Loger.getLoger('PC-Slideshow');
class Slideshow extends Ape {
    constructor() {
        super();
        this._timer = null;
        this.windowWidth = 0;
        this.num = 0;
        this.len = 0;
        this.addEvent();
        this.init();
    }

    init() {
        $(window).on('resize',this._imgReload.bind(this));
        this.slideImg();
        this._imgReload();
        $(".slidesImg").on('load', this._onLoadImage.bind(this));
        $('#dots').on('mouseenter',this._mouseenterHandler.bind(this));
        $('#dots').on('mouseleave',this._mouseleaveHandler.bind(this));
    }

    addEvent() {

    }
    _onLoadImage(){
        this._imgReload();
    }
    slideImg(){


        let oli = document.getElementById('dots').getElementsByTagName("li");
        let _num = 0;

        let clone=$(".slidesMap").first().clone();
        $("#motionMapBox").append(clone);

        let li = document.getElementById('motionMapBox').getElementsByTagName("li");
        let size = li.length
        this.num = _num;
        this.len = size;

        this._timer = setInterval(function(){
            li[_num].style.display="none";
            _num=++_num==size ? 0:_num;
            li[_num].style.display="inline-block";
            // $("#motionMapBox").stop().animate({left:-this.num*this.windowWidth},500);
            $("#dots li").eq(_num).addClass('active').siblings().removeClass('active');

        },3000);//切换时间
    }
    _mouseenterHandler(){
        clearInterval(this._timer);
    }
    _mouseleaveHandler(){
        setInterval(this._timer);
    }
    _move(){
        let li = document.getElementById('motionMapBox').getElementsByTagName("li");
        this._timer = setInterval(function(){
            li[_num].style.display="none";
             _num=++_num==size ? 0:_num;
             li[_num].style.display="inline-block";
           // $("#motionMapBox").stop().animate({left:-this.num*this.windowWidth},500);
            $("#dots li").eq(_num).addClass('active').siblings().removeClass('active');

        },3000);//切换时间
    }
    slideImg(){

        let i = 0;
        let width = $('.slidesMap').width();
        let clone=$(".slidesMap").first().clone();
        $("#motionMapBox").append(clone);
        let size = document.getElementById('motionMapBox').getElementsByTagName("li").length;
        for(let j=0;j<size-1;j++){
            $("#dots").append("<li></li>");
        }
        $("#dots li").first().addClass('active');

       /* $(".dots li").hover(function(){
            let index=$(this).index();
            i=index;
            $(".motionMapBox").stop().animate({left:-index*width},500);
            $(this).addClass('active').siblings().removeClass('active');
        })*/
           /* let t=setInterval(function(){
                i++;
                move();
            },2000);

            //对banner定时器的操作
            $(".slideshow").hover(function(){
                clearInterval(t);
            },function(){
                t=setInterval(move,2000);
            })*/


            /*function move(){
                if(i==size){
                    $("#motionMapBox").css({left:0});
                    i=1;
                }
                if(i==-1){
                    $("#motionMapBox").css({left:-(size-1)*width});
                    i=size-2;
                }

                $("#motionMapBox").stop().animate({left:-i*width},500);

                if(i==size-1){
                    $("#dots li").eq(0).addClass('active').siblings().removeClass('active');
                }else{
                    $("#dots li").eq(i).addClass('active').siblings().removeClass('active');
                }
            }*/

    }
    _imgReload(){
        let _windowWidth = $("body").width();
        this.windowWidth = _windowWidth;
        $('.slidesMap').css({width:_windowWidth + "px"});
        $('.slidesImg').css({width:_windowWidth + "px"});

  /*      let imgHeight = 0;

        let wtmp = $("body").width();


        $("#motionMapBox li").each(function(){

            $(this).css({width:wtmp + "px"});

        });

        $(".slidesImg").each(function(){

            $(this).css({width:wtmp + "px"});

            imgHeight = $(this).height();

        });*/
        $('#motionMapBox').width($(".slidesMap").length * _windowWidth)
    }


}
export default new Slideshow;