1

I'm using on my website jQuery Mousewheel to have an horizontal scrolling.

I'm trying to get the offset right of an image when scrolling.

when using $(document).ready it works, but when I try to use $(window).scroll I dont have the right offset and the offset is not updated when scrolling.

any ideas ?

here is my code :

$(document).ready(function() {

  $('html, body, *').mousewheel(function(e, delta) {

     this.scrollLeft -= (delta);
     e.preventDefault();
  });

});

$(window).scroll(function() {

  var $image = $(".image_test");
  var $rt = ($("body").width() - ($image.offset().left + $image.outerWidth()));

  console.log($rt);

});

here is a Jsfiddle :

https://jsfiddle.net/deapzuc4/

thanks

mmdwc
  • 1,095
  • 6
  • 27
  • 53

1 Answers1

0

add the scroll positioning to your calculation as well:

var $rt = ($("body").width() - ($image.offset().left + $(window).scrollLeft() + $image.outerWidth()));
Evik Ghazarian
  • 1,803
  • 1
  • 9
  • 24