From 4d9b76676bf3b3f7bea59759bff827fe7f918fc2 Mon Sep 17 00:00:00 2001 From: nael Date: Wed, 14 Aug 2019 17:44:18 +0200 Subject: [PATCH] wip #2747 @7 --- public/_modules/home-slider/index.html | 8 +-- public/_modules/home-slider/slider-jq.js | 76 ++++++++++++------------ 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/public/_modules/home-slider/index.html b/public/_modules/home-slider/index.html index 029ad7c..c328145 100644 --- a/public/_modules/home-slider/index.html +++ b/public/_modules/home-slider/index.html @@ -75,7 +75,7 @@
- +
@@ -111,7 +111,7 @@
- +
@@ -148,7 +148,7 @@
- +
@@ -184,7 +184,7 @@
- +
diff --git a/public/_modules/home-slider/slider-jq.js b/public/_modules/home-slider/slider-jq.js index d429bf6..def116a 100644 --- a/public/_modules/home-slider/slider-jq.js +++ b/public/_modules/home-slider/slider-jq.js @@ -23,7 +23,6 @@ this.final = 'px 0px)'; this.container = this.element.find('.slider'); - this.hammerSwipe.get('swipe').set({ enable: true }); this.initt(); }; @@ -44,10 +43,16 @@ $(window).on('resize', function () { $this.resize(); }); + + this.autoSlideDelay = 4; // automatic slideshow delay + this.slideInterval = window.setTimeout(function () { + $this.nextSlide(); + }, this.autoSlideDelay*1000); + this.resize(); this.initSwipeEvent(); this.enableArrows(); - // this.automaticSlideshow(); + this.automaticSlideshow(); this.indicator(); }, @@ -102,7 +107,12 @@ $this.hammerSwipe.get('swipe').set({enable: true}); // swipe functionality is now reactivate $this.currentSlideIndex.removeClass('active').eq($this.index); + $this.slideInterval = setTimeout(function () { + $this.nextSlide(); + }, $this.autoSlideDelay*1000); + $this.enableArrows(); // when animation is finished we reactivate click event + $this.automaticSlideshow(); TweenMax.set($this.element.find('.slide-img'), { clip: $this.init + $this.width + 'px ' + $this.height + $this.final, ease: Power3.easeOut @@ -110,7 +120,7 @@ }; - if ($(window).width() > 768) { + if ($(window).outerWidth() > 768) { TweenMax.set($this.element.find('.slide-img'), { clip: $this.init + $this.width + 'px ' + $this.height + $this.final, ease: Power3.easeOut @@ -204,57 +214,45 @@ indicator: function(){ let $this= this; $('.slider-position').on('click',function () { - let direction = -1; - let pos = $(this).data('position'); + let direction = 1; + let nextPosition= $(this).data('position'); + let currentPosition = $this.index; + + clearTimeout($this.slideInterval); - if (posdirection){ - this.direction = 1; + else if(currentPosition > nextPosition){ + direction = -1; } - else if(pos=direction){ - this.goToSlide(pos,direction).off(); + else if(currentPosition == nextPosition){ + return false; } - console.log(pos,direction); - - // DETERMINER la direction en fonction de la position - $this.goToSlide(pos,direction); - // console.log(direction); + $this.goToSlide(nextPosition,direction); }); }, - // autoSlide: function () { - // let $this = this; - // - // let myVar = setInterval(function () { - // $this.nextSlide(); - // }, 4000); - // }, - - // automaticSlideshow:function(){ - // // this.autoSlide(); - // - // let $this = this; - // - // let myVar = setInterval(function () { - // $this.nextSlide(); - // }, 4000); - // - // $(".arrow").on('click',function () { - // // $this.autoSlide.off(); - // // clearInterval(myVar); - // // alert('test'); - // }) - // }, + automaticSlideshow:function(){ + + let $this = this; + this.element.find(".arrow").on('click',function () { + // window.clearTimeout($this.slideInterval); + window.clearTimeout($this.slideInterval); + + alert($this.slideInterval); + }); + }, initSwipeEvent: function (){ let $this = this; this.hammerSwipe.on('swiperight', function() { $this.prevSlide(); + clearTimeout($this.slideInterval); }); this.hammerSwipe.on('swipeleft', function() { $this.nextSlide(); + clearTimeout($this.slideInterval); }); }, -- 2.39.5