Created
August 17, 2015 06:37
-
-
Save prosenjit-manna/f9b827d96219ee93cae4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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