'Is there a possibility to limit the jQuery background image scroll?

I have a jQuery Script for changing the background-position of a background-image while scrolling down the page.

The issue is that I want to change the background-position until the image arrives at background-position "bottom" because otherwise the background-image ends and the overflow is visible.

jQuery(window).bind("load resize scroll", function(e) {
  var y = jQuery(window).scrollTop();
  
  jQuery(".hero").filter(function() {
    return jQuery(this).offset().top < (y + jQuery(window).height()) &&
      jQuery(this).offset().top + jQuery(this).height() > y;
  }).css('background-position', '0px ' + parseInt(-y / 10) + 'px');
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source