Created
December 5, 2012 19:53
-
-
Save nathanaelnsmith/4218918 to your computer and use it in GitHub Desktop.
A jQuery plugin that changes a background images position to fixed once you've scrolled the page to the bottom of the image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.bgScrollFix = function() { | |
var imageSrc = this.css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "").split(',')[0]; | |
var image = new Image(); | |
image.src = imageSrc; | |
$(window).scroll(function(){ | |
if((image.height - $(window).height()) <= $(window).scrollTop()) { | |
$('body').addClass('fixed'); | |
} else { | |
$('body').removeClass('fixed'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment