From d41a2baf9b9a5a89f7855f7c14077b8ad45aa7f5 Mon Sep 17 00:00:00 2001 From: nael Date: Fri, 12 Jul 2019 18:20:38 +0200 Subject: [PATCH] wip #2747 @7 --- public/_modules/home-slider/index.html | 2 +- public/_modules/home-slider/slider.js | 60 +++++++++++++++----------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/public/_modules/home-slider/index.html b/public/_modules/home-slider/index.html index b007235..6aaecf6 100644 --- a/public/_modules/home-slider/index.html +++ b/public/_modules/home-slider/index.html @@ -60,7 +60,7 @@
-
+
diff --git a/public/_modules/home-slider/slider.js b/public/_modules/home-slider/slider.js index 056788b..5c45053 100644 --- a/public/_modules/home-slider/slider.js +++ b/public/_modules/home-slider/slider.js @@ -13,47 +13,57 @@ let getImg = new Image(); let img = document.getElementsByClassName('.img-slider'), imgHeight = getImg.naturalHeight, imgWidth = getImg.naturalWidth; + // console.log('valeur initial img => '+imgWidth,imgHeight); -let width = $('.slide-img').width(), - height = $('.slide-img').height(), +let width = $('.slide-img').width(), // --> clip container width + height = $('.slide-img').height(), // --> clip container height init = 'rect(0px ', final = 'px 0px)'; - // $(".slide-img").css('clip', 'rect(0px, '+width +'px,'+height +' px, 0px)'); - console.log('SANS resize '+width,height); - -$('.img-slider').each(function () { - getImg = $(this).attr("src"); - console.log(getImg); - - let widthFactor= width / imgWidth, // coef multiplicateur width - heightFactor= height / imgHeight ; // coef multiplicateur height - - console.log(widthFactor,heightFactor); - $(this).css({'width':imgWidth*Math.max(widthFactor, heightFactor), 'height':imgHeight*Math.max(widthFactor, heightFactor)}); - -}); +resize(); $(window).on('orientationchange',function () { resize(); setTimeout(function () { resize(); - },1000); + },500); }); $(window).on('resize',function () { resize(); }); -resize(); // // RESIZE function resize() { + $('.img-slider').each(function () { + let width = $('.slide-img').eq(index).width(), // --> + height = $('.slide-img').eq(index).height(); + + let naturalHeight = $(this).prop('naturalHeight'), + naturalWidth = $(this).prop('naturalWidth'); + + let getAllImg = new Image(); + getAllImg.src = $(this).attr("src"); + + console.log(getAllImg); // --> return toutes les img avec leur attributs src - let width = $('.slide-img').eq(index).width(), - height = $('.slide-img').eq(index).height(); + console.log('img natural values: '+naturalWidth,naturalHeight); - console.log(width, height); - // $('.slide-img').css({'width': width ,'height':height}); + let widthFactor = width / naturalWidth, // coef multiplicateur width + heightFactor = height / naturalHeight ; // coef multiplicateur height + TweenMax.set($(this),{width:naturalWidth*Math.max(widthFactor, heightFactor), height:naturalHeight*Math.max(widthFactor, heightFactor)}); + + // console.log('valeurs des facteurs de multiplication: '+widthFactor,heightFactor); + }); + + $('.slide-img').each(function () { + let width = $(this).width(), // --> container width (clip container) + height = $(this).height(); // --> container height (clip container) + + TweenMax.set($(this),{clip:init + width +'px '+ height+ final, ease: Power3.easeOut}); + + console.log('container --> '+ width,height); + }); } function GotoSlide(nextindex, direction){ @@ -72,13 +82,12 @@ function GotoSlide(nextindex, direction){ nextContainerImg = $('.slide-img').eq(nextindex); console.log(nextindex, direction); - TweenMax.set('.slide-img',{clip:init + width +'px '+ height+ final, ease: Power3.easeOut}); + TweenMax.set($('.slide-img'),{clip:init + width +'px '+ height+ final, ease: Power3.easeOut}); let tl = new TimelineMax({onComplete: isSlideRunning}); tl.set(currentSlideIndex,{zIndex: 97}); tl.set(nextText,{opacity:1,x:0}); tl.to(currentText,0.5*Delay,{x:-80*direction,opacity:0, ease: Power1.easeOut}); - tl.to(currentContainerImg,2*Delay,{ clip: init+ (direction)*-1*imgWidth+'px,'+ height+'px,'+ (direction)*-1*imgWidth+'px', ease: Power2.easeInOut }, "-="+0.8*Delay); tl.from(nextText,0.5*Delay,{x:80*direction,opacity:0,ease: Power1.easeOut},'-='+1.2*Delay); @@ -112,6 +121,7 @@ function GotoSlide(nextindex, direction){ } $('.arrow').on('click',function () { + resize(); if($(this).is('.next')){ direction = 1; } @@ -120,4 +130,4 @@ $('.arrow').on('click',function () { } let nextindex = (index +direction + slideLength)% slideLength; GotoSlide(nextindex,direction); -}); +}); \ No newline at end of file -- 2.39.5