Skip to content

Instantly share code, notes, and snippets.

@prosenjit-manna
Created August 17, 2015 06:37
Show Gist options
  • Save prosenjit-manna/f9b827d96219ee93cae4 to your computer and use it in GitHub Desktop.
Save prosenjit-manna/f9b827d96219ee93cae4 to your computer and use it in GitHub Desktop.
// Paralax Plugin
(function($) {
$.fn.parallax = function(options) {
var windowHeight = $(window).height();
var settings = $.extend({
speed : 0.15,
topMinus : 500
}, options);
return this.each( function() {
var $this = $(this);
$(document).scroll(function(){
var scrollTop = $(window).scrollTop();
var offset = $this.offset().top;
var height = $this.outerHeight();
if (offset + height <= scrollTop || offset >= scrollTop + windowHeight) {
return;
}
var yBgPosition = Math.round((offset - scrollTop) * settings.speed)-settings.topMinus;
$this.css('background-position', 'center ' + yBgPosition + 'px');
});
});
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment