-
Notifications
You must be signed in to change notification settings - Fork 28
/
jquery.scrollParallax.min.js
15 lines (15 loc) · 2.32 KB
/
jquery.scrollParallax.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*!
* Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
* backgroundPosition cssHook for jquery. Necessary to combat different css property names between browsers
* https://github.com/brandonaaron/jquery-cssHooks
* Licensed under the MIT License (LICENSE.txt).
*/
(function(c){var a=c('<div style="background-position: 3px 5px">');c.support.backgroundPosition=a.css("backgroundPosition")==="3px 5px"?true:false;c.support.backgroundPositionXY=a.css("backgroundPositionX")==="3px"?true:false;a=null;var d=["X","Y"];function b(g){var f=g.split(/\s/),e={X:f[0],Y:f[1]};return e}if(!c.support.backgroundPosition&&c.support.backgroundPositionXY){c.cssHooks.backgroundPosition={get:function(g,f,e){return c.map(d,function(h,j){return c.css(g,"backgroundPosition"+h)}).join(" ")},set:function(e,f){c.each(d,function(j,g){var h=b(f);e.style["backgroundPosition"+g]=h[g]})}}}if(c.support.backgroundPosition&&!c.support.backgroundPositionXY){c.each(d,function(f,e){c.cssHooks["backgroundPosition"+e]={get:function(j,i,g){var h=b(c.css(j,"backgroundPosition"));return h[e]},set:function(h,j){var g=b(c.css(h,"backgroundPosition")),i=e==="X";h.style.backgroundPosition=(i?j:g.X)+" "+(i?g.Y:j)}};c.fx.step["backgroundPosition"+e]=function(g){c.cssHooks["backgroundPosition"+e].set(g.elem,g.now+g.unit)}})}})(jQuery);
/*!
* Scroll-based parallax plugin for jQuery
* Copyright (c) 2011 Dave Cranwell (http://davecranwell.com)
* Licensed under the MIT License.
* 2011-05-18
* version 1.0
*/
(function(a){a.fn.scrollParallax=function(c){var d={speed:0.2,axis:"x,y",debug:false};function b(e){if(d.debug&&"console" in window&&"log" in window.console){console.log(e)}}return this.each(function(){var h=a(this);if(c){a.extend(d,c)}h.bind("inview",function(i,j){if(j==true){h.addClass("inview");b("in view")}else{h.removeClass("inview");b("out of view")}});var f=h.css("backgroundPosition").split(" ");var g=parseInt(f[0].replace(/[^0-9\-]/g,""));var e=parseInt(f[1].replace(/[^0-9\-]/g,""));a(window).bind("scroll",function(){if(h.hasClass("inview")){var l=h.offset();if(d.axis.match(/x/)){var m=l.left-a(window).scrollLeft();var k=(-(m)*d.speed)+g}else{var k=g}if(d.axis.match(/y/)){var j=l.top-a(window).scrollTop();var i=(-(j)*d.speed)+e}else{var i=e}b("new X position: "+k);b("new Y position: "+i);h.css({backgroundPosition:parseInt(k)+"px "+parseInt(i)+"px"})}})})}})(jQuery);