let animationDuration = 0; // durée de l'animation
let delayBetweenAnim = 2000; // delay entre chaque slide
let mouvement = 0; // valeur en px du déplacement des blocks
+let Delay = 1;
+let isRunning = false;
+// Get on screen image
+let screenImage = $(".img-slider");
-let pending = false;
+// Create new offscreen image to test
+let theImage = new Image();
+theImage.src = screenImage.attr("src");
-let width = $('.slide-img').width(),
+let img = document.getElementsByClassName('.img-slider'),
+ width = $('.slide-img').width(),
height = $('.slide-img').height(),
- imgWidth =$('.img-slider').width(),
+ imgHeight = theImage.height,
+ imgWidth = theImage.width,
init = 'rect(0px ',
final = 'px 0px)';
+$('.img-slider').each(function () {
+ $(this).css({'width':imgWidth, 'height':imgHeight});
+});
+
+// $('.img-slider').css({'width':imgWidth, 'height':imgHeight});
+console.log(imgWidth,imgHeight);
+console.log('Container width: '+width+' ---- Container height: '+height);
+
+
+
+
function GotoSlide(nextindex, direction){
+ if (!isRunning){
+ isRunning = true;
+
let currentSlideIndex = $('.slide').eq(index),
nextSlideIndex = $('.slide').eq(nextindex),
currentText = $('.slide-txt').eq(index),
nextIndicatorIndex = $('.slider-position').eq(nextindex),
nextContainerImg = $('.slide-img').eq(nextindex);
+ $(window).resize(function () {
+
+ let width = $('.slide-img').width(),
+ height = $('.slide-img').height(),
+ imgHeight = theImage.height,
+ imgWidth = theImage.width;
+
+ TweenMax.set('.img-slider',{clip:init + imgWidth +'px '+ imgHeight+ final, ease: Power3.easeOut});
+
+ console.log('%c Image width: '+imgWidth+' ---- image height: '+imgHeight,'background: #222; color: #bada55');
+ console.log('Container width: '+width+' ---- Container height: '+height);
+ });
+
console.log(nextindex, direction);
TweenMax.set('.img-slider',{clip:init + width +'px '+ height+ final, ease: Power3.easeOut});
- let tl = new TimelineMax();
+ let tl = new TimelineMax({onComplete: isSlideRunning});
tl.set(currentSlideIndex,{zIndex: 97});
tl.set(nextText,{opacity:1,x:0});
- tl.to(currentText,0.5,{x:-50*direction,opacity:0});
+ tl.to(currentText,0.5*Delay,{x:-80*direction,opacity:0, ease: Power1.easeOut});
- // tl.to(currentImg,2,{clip:init +width*(direction)*-1 +'px '+ height+ 'px'+ '-'+imgWidth+'px', ease: Power2.easeInOut,},"-=0.8");
+ tl.to(currentImg,2*Delay,{ clip: init+ (direction)*-1*imgWidth+'px,'+ height+'px,'+ (direction)*-1*imgWidth+'px', ease: Power2.easeInOut }, "-="+0.8*Delay);
- if(direction === -1){
- tl.to(currentImg,2,{ clip: init+ imgWidth+'px,'+ height+'px,'+ imgWidth+'px', ease: Power2.easeInOut }, "-=0.8");
- }else{
- tl.to(currentImg,2,{ clip: init+ '-'+imgWidth+'px,'+ height+'px,'+ '-'+imgWidth+'px', ease: Power2.easeInOut }, "-=0.8");
- }
-
- tl.from(nextText,0.5,{x:80*direction,opacity:0},'-=1.4');
- tl.from(nextContainerImg,0.8,{x:150*direction,ease: Power2.easeInOut},'-=1.8');
- tl.to(currentContainerImg,0.8,{x:-250*direction,ease: Power2.easeInOut},"-=1.8");
+ tl.from(nextText,0.5*Delay,{x:80*direction,opacity:0,ease: Power1.easeOut},'-='+1.2*Delay);
+ tl.from(nextContainerImg,1.5*Delay,{x:150*direction,ease: Power2.easeInOut},'-='+2.3*Delay);
+ tl.to(currentContainerImg,1.5*Delay,{x:-250*direction,ease: Power2.easeInOut},"-="+1.9*Delay);
tl.set(currentSlideIndex,{zIndex: 0});
- // tl.set(nextContainerImg,{x: 0});
tl.set(currentContainerImg,{x:0});
-
- // tl.set(currentText,{opacity:1});
- // tl.to(currentText,1,{x:-200,opacity:0});
- // tl.set(currentSlideIndex,{zIndex: 999});
- // tl.set(nextText,{opacity:0});
- // tl.to(currentImg,1,{clip:init + '-'+width +'px '+ height+ final, ease: Power1.easeIn},'-=0.5');
- // tl.from(nextText,1,{x:200,opacity:0},'-=0.5');
- // tl.set(currentText,{opacity:1,x:0});
- // tl.set(currentSlideIndex,{zIndex: 0});
-
-
nextIndicatorIndex.addClass('active-indicator').eq(nextindex);
currentIndicatorIndex.removeClass('active-indicator').eq(index);
setTimeout(function () {
currentSlideIndex.removeClass('active').eq(index);
- },1000);
+ },1000*Delay);
index=nextindex;
+
+ function isSlideRunning(){
+ isRunning = false;
+ }
+
+ }
+ else{
+ return false;
+ }
}
$('.arrow').on('click',function () {
direction=-1;
}
let nextindex = (index +direction + slideLength)% slideLength;
-
GotoSlide(nextindex,direction);
});