Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swiper, how to get translateX real-time?

I want to get translateX of swiper-wrapper real-time. I will use the real-time translateX to do some works.

swiper.on('sliderMove', function onSliderMove() {
  console.log(this.getTranslate(), this.translate); //-64 -64, or maybe other value, but not -320
});

I listen to sliderMove event, but the result is not correct.

I inspect the swiper-wrapper element, the style is

transition-duration: 0ms; 
transform: translate3d(-320px, 0px, 0px);

I expect the value of this.getTranslate() should be -320, not -64

like image 852
slideshowp2 Avatar asked Jan 22 '18 06:01

slideshowp2


1 Answers

listen on setTranslate event will work.

swiper.on('setTranslate', function onSliderMove() {
  console.log(this.translate);
});
like image 141
slideshowp2 Avatar answered Oct 06 '22 15:10

slideshowp2