Skip to content

Instantly share code, notes, and snippets.

@koirikivi
Created November 8, 2013 06:19
Show Gist options
  • Save koirikivi/7366971 to your computer and use it in GitHub Desktop.
Save koirikivi/7366971 to your computer and use it in GitHub Desktop.
function polyFillBgFixed($this, imgWidth, imgHeight, paddingTop) {
var paddingTop = paddingTop || 0,
thisHeight = $this.height();
$this.css("background-attachment", "scroll");
setInterval(function() {
var $window = $(window),
thisTop = $this.offset().top + (paddingTop || 0),
windowBottom = $window.scrollTop() + $window.height(),
w = $window.width() / imgWidth;
y = (windowBottom - thisTop) / ($window.height());
var imgPos = -imgHeight * w + (imgHeight * w * y);
imgPos = Math.round(imgPos);
$this.css("background-position-y", imgPos + "px");
}, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment