From 374a74926bba91f2beb106eb0b628edfa9f31957 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Thu, 29 Jan 2015 03:40:08 -0600 Subject: [PATCH] clean up some unused variables and compress the minified script --- parallax.js | 22 ++++++++++------------ parallax.min.js | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/parallax.js b/parallax.js index b43c972..5af6f7b 100755 --- a/parallax.js +++ b/parallax.js @@ -19,7 +19,7 @@ } if (!window.requestAnimationFrame) - window.requestAnimationFrame = function(callback, element) { + window.requestAnimationFrame = function(callback) { var currTime = new Date().getTime(); var timeToCall = Math.max(0, 16 - (currTime - lastTime)); var id = window.setTimeout(function() { callback(currTime + timeToCall); }, @@ -37,9 +37,6 @@ // Parallax Constructor - var $body = $('body'); - var $window = $(window); - function Parallax(element, options) { var self = this; @@ -263,19 +260,20 @@ setup: function() { if (this.isReady) return; - $window - .on('scroll.px.parallax load.px.parallax', function() { + var $doc = $(document), $win = $(window); + + $win.on('scroll.px.parallax load.px.parallax', function() { var scrollTopMax = Parallax.docHeight - Parallax.winHeight; var scrollLeftMax = Parallax.docWidth - Parallax.winWidth; - Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, $window.scrollTop())); - Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $window.scrollLeft())); + Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, $win.scrollTop())); + Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft())); Parallax.requestRender(); }) .on('resize.px.parallax load.px.parallax', function() { - Parallax.winHeight = $window.height(); - Parallax.winWidth = $window.width(); - Parallax.docHeight = $(document).height(); - Parallax.docWidth = $(document).width(); + Parallax.winHeight = $win.height(); + Parallax.winWidth = $win.width(); + Parallax.docHeight = $doc.height(); + Parallax.docWidth = $doc.width(); Parallax.isFresh = false; Parallax.requestRender(); }); diff --git a/parallax.min.js b/parallax.min.js index d7d9e85..0a209e9 100644 --- a/parallax.min.js +++ b/parallax.min.js @@ -3,4 +3,4 @@ * @copyright 2014 PixelCog, Inc. * @license MIT (https://github.com/pixelcog/parallax.js/blob/master/LICENSE) */ -(function($,window,document,undefined){(function(){var lastTime=0;var vendors=["ms","moz","webkit","o"];for(var x=0;x").prependTo("body");this.$slider=$("").prependTo(this.$mirror);this.$mirror.addClass("parallax-mirror").css({visibility:"hidden",zIndex:this.zIndex,position:"fixed",top:0,left:0,overflow:"hidden"});this.$slider.addClass("parallax-slider").one("load",function(){if(!self.naturalHeight||!self.naturalWidth){self.naturalHeight=this.naturalHeight||this.height||1;self.naturalWidth=this.naturalWidth||this.width||1}self.aspectRatio=self.naturalWidth/self.naturalHeight;Parallax.isSetup||Parallax.setup();Parallax.sliders.push(self);Parallax.isFresh=false;Parallax.requestRender()});this.$slider[0].src=this.imageSrc;if(this.naturalHeight&&this.naturalWidth||this.$slider[0].complete){this.$slider.trigger("load")}}$.extend(Parallax.prototype,{speed:.2,bleed:0,zIndex:-100,iosFix:true,androidFix:true,position:"center",refresh:function(){this.boxWidth=this.$element.outerWidth();this.boxHeight=this.$element.outerHeight()+this.bleed*2;this.boxOffsetTop=this.$element.offset().top-this.bleed;this.boxOffsetLeft=this.$element.offset().left;this.boxOffsetBottom=this.boxOffsetTop+this.boxHeight;var winHeight=Parallax.winHeight;var docHeight=Parallax.docHeight;var maxOffset=Math.min(this.boxOffsetTop,docHeight-winHeight);var minOffset=Math.max(this.boxOffsetTop+this.boxHeight-winHeight,0);var imageHeightMin=this.boxHeight+(maxOffset-minOffset)*(1-this.speed)|0;var imageOffsetMin=(this.boxOffsetTop-maxOffset)*(1-this.speed)|0;if(imageHeightMin*this.aspectRatio>=this.boxWidth){this.imageWidth=imageHeightMin*this.aspectRatio|0;this.imageHeight=imageHeightMin;this.offsetBaseTop=imageOffsetMin;var margin=this.imageWidth-this.boxWidth;if(this.positionX=="left"){this.offsetLeft=0}else if(this.positionX=="right"){this.offsetLeft=-margin}else if(!isNaN(this.positionX)){this.offsetLeft=Math.max(this.positionX,-margin)}else{this.offsetLeft=-margin/2|0}}else{this.imageWidth=this.boxWidth;this.imageHeight=this.boxWidth/this.aspectRatio|0;this.offsetLeft=0;var margin=this.imageHeight-imageHeightMin;if(this.positionY=="top"){this.offsetBaseTop=imageOffsetMin}else if(this.positionY=="bottom"){this.offsetBaseTop=imageOffsetMin-margin}else if(!isNaN(this.positionY)){this.offsetBaseTop=imageOffsetMin+Math.max(this.positionY,-margin)}else{this.offsetBaseTop=imageOffsetMin-margin/2|0}}},render:function(){var scrollTop=Parallax.scrollTop;var scrollLeft=Parallax.scrollLeft;var scrollBottom=scrollTop+Parallax.winHeight;if(this.boxOffsetBottom>scrollTop&&this.boxOffsetTop").prependTo("body"),this.$slider=t("").prependTo(this.$mirror),this.$mirror.addClass("parallax-mirror").css({visibility:"hidden",zIndex:this.zIndex,position:"fixed",top:0,left:0,overflow:"hidden"}),this.$slider.addClass("parallax-slider").one("load",function(){h.naturalHeight&&h.naturalWidth||(h.naturalHeight=this.naturalHeight||this.height||1,h.naturalWidth=this.naturalWidth||this.width||1),h.aspectRatio=h.naturalWidth/h.naturalHeight,o.isSetup||o.setup(),o.sliders.push(h),o.isFresh=!1,o.requestRender()}),this.$slider[0].src=this.imageSrc,void((this.naturalHeight&&this.naturalWidth||this.$slider[0].complete)&&this.$slider.trigger("load")))}function h(s){return this.each(function(){var h=t(this),n="object"==typeof s&&s;this==i||this==e||h.is("body")?o.configure(n):h.data("px.parallax")||(n=t.extend({},h.data(),n),h.data("px.parallax",new o(this,n))),"string"==typeof s&&o[s]()})}!function(){for(var t=0,e=["ms","moz","webkit","o"],s=0;s=this.boxWidth){this.imageWidth=h*this.aspectRatio|0,this.imageHeight=h,this.offsetBaseTop=n;var r=this.imageWidth-this.boxWidth;this.offsetLeft="left"==this.positionX?0:"right"==this.positionX?-r:isNaN(this.positionX)?-r/2|0:Math.max(this.positionX,-r)}else{this.imageWidth=this.boxWidth,this.imageHeight=this.boxWidth/this.aspectRatio|0,this.offsetLeft=0;var r=this.imageHeight-h;this.offsetBaseTop="top"==this.positionY?n:"bottom"==this.positionY?n-r:isNaN(this.positionY)?n-r/2|0:n+Math.max(this.positionY,-r)}},render:function(){var t=o.scrollTop,i=o.scrollLeft,e=t+o.winHeight;this.visibility=this.boxOffsetBottom>t&&this.boxOffsetTop