vendor: 11,990 bytes, lines 1-400
1/*! 2 * parallax.js v1.4.2 (http://pixelcog.github.io/parallax.js/) 3 * @copyright 2016 PixelCog, Inc. 4 * @license MIT (https://github.com/pixelcog/parallax.js/blob/master/LICENSE) 5 */ 6 7;(function ( $, window, document, undefined ) { 8 9 // Polyfill for requestAnimationFrame 10 // via: https://gist.github.com/paulirish/1579671 11 12 (function() { 13 var lastTime = 0; 14 var vendors = ['ms', 'moz', 'webkit', 'o']; 15 for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { 16 window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; 17 window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] 18 || window[vendors[x]+'CancelRequestAnimationFrame']; 19 } 20 21 if (!window.requestAnimationFrame) 22 window.requestAnimationFrame = function(callback) { 23 var currTime = new Date().getTime(); 24 var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 25 var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 26 timeToCall); 27 lastTime = currTime + timeToCall; 28 return id; 29 }; 30 31 if (!window.cancelAnimationFrame) 32 window.cancelAnimationFrame = function(id) { 33 clearTimeout(id); 34 }; 35 }()); 36 37 38 // Parallax Constructor 39 40 function Parallax(element, options) { 41 var self = this; 42 43 if (typeof options == 'object') { 44 delete options.refresh; 45 delete options.render; 46 $.extend(this, options); 47 } 48 49 this.$element = $(element); 50 51 if (!this.imageSrc && this.$element.is('img')) { 52 this.imageSrc = this.$element.attr('src'); 53 } 54 55 var positions = (this.position + '').toLowerCase().match(/\S+/g) || []; 56 57 if (positions.length < 1) { 58 positions.push('center'); 59 } 60 if (positions.length == 1) { 61 positions.push(positions[0]); 62 } 63 64 if (positions[0] == 'top' || positions[0] == 'bottom' || positions[1] == 'left' || positions[1] == 'right') { 65 positions = [positions[1], positions[0]]; 66 } 67 68 if (this.positionX != undefined) positions[0] = this.positionX.toLowerCase(); 69 if (this.positionY != undefined) positions[1] = this.positionY.toLowerCase(); 70 71 self.positionX = positions[0]; 72 self.positionY = positions[1]; 73 74 if (this.positionX != 'left' && this.positionX != 'right') { 75 if (isNaN(parseInt(this.positionX))) { 76 this.positionX = 'center'; 77 } else { 78 this.positionX = parseInt(this.positionX); 79 } 80 } 81 82 if (this.positionY != 'top' && this.positionY != 'bottom') { 83 if (isNaN(parseInt(this.positionY))) { 84 this.positionY = 'center'; 85 } else { 86 this.positionY = parseInt(this.positionY); 87 } 88 } 89 90 this.position = 91 this.positionX + (isNaN(this.positionX)? '' : 'px') + ' ' + 92 this.positionY + (isNaN(this.positionY)? '' : 'px'); 93 94 if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) { 95 if (this.imageSrc && this.iosFix && !this.$element.is('img')) { 96 this.$element.css({ 97 backgroundImage: 'url(' + this.imageSrc + ')', 98 backgroundSize: 'cover', 99 backgroundPosition: this.position 100 }); 101 } 102 return this; 103 } 104 105 if (navigator.userAgent.match(/(Android)/)) { 106 if (this.imageSrc && this.androidFix && !this.$element.is('img')) { 107 this.$element.css({ 108 backgroundImage: 'url(' + this.imageSrc + ')', 109 backgroundSize: 'cover', 110 backgroundPosition: this.position 111 }); 112 } 113 return this; 114 } 115 116 this.$mirror = $('<div />').prependTo('body'); 117 118 var slider = this.$element.find('>.parallax-slider'); 119 var sliderExisted = false; 120 121 if (slider.length == 0) 122 this.$slider = $('<img />').prependTo(this.$mirror); 123 else { 124 this.$slider = slider.prependTo(this.$mirror) 125 sliderExisted = true; 126 } 127 128 this.$mirror.addClass('parallax-mirror').css({ 129 visibility: 'hidden', 130 zIndex: this.zIndex, 131 position: 'fixed', 132 top: 0, 133 left: 0, 134 overflow: 'hidden' 135 }); 136 137 this.$slider.addClass('parallax-slider').one('load', function() { 138 if (!self.naturalHeight || !self.naturalWidth) { 139 self.naturalHeight = this.naturalHeight || this.height || 1; 140 self.naturalWidth = this.naturalWidth || this.width || 1; 141 } 142 self.aspectRatio = self.naturalWidth / self.naturalHeight; 143 144 Parallax.isSetup || Parallax.setup(); 145 Parallax.sliders.push(self); 146 Parallax.isFresh = false; 147 Parallax.requestRender(); 148 }); 149 150 if (!sliderExisted) 151 this.$slider[0].src = this.imageSrc; 152 153 if (this.naturalHeight && this.naturalWidth || this.$slider[0].complete || slider.length > 0) { 154 this.$slider.trigger('load'); 155 } 156 157 }; 158 159 160 // Parallax Instance Methods 161 162 $.extend(Parallax.prototype, { 163 speed: 0.2, 164 bleed: 0, 165 zIndex: -100, 166 iosFix: true, 167 androidFix: true, 168 position: 'center', 169 overScrollFix: false, 170 171 refresh: function() { 172 this.boxWidth = this.$element.outerWidth(); 173 this.boxHeight = this.$element.outerHeight() + this.bleed * 2; 174 this.boxOffsetTop = this.$element.offset().top - this.bleed; 175 this.boxOffsetLeft = this.$element.offset().left; 176 this.boxOffsetBottom = this.boxOffsetTop + this.boxHeight; 177 178 var winHeight = Parallax.winHeight; 179 var docHeight = Parallax.docHeight; 180 var maxOffset = Math.min(this.boxOffsetTop, docHeight - winHeight); 181 var minOffset = Math.max(this.boxOffsetTop + this.boxHeight - winHeight, 0); 182 var imageHeightMin = this.boxHeight + (maxOffset - minOffset) * (1 - this.speed) | 0; 183 var imageOffsetMin = (this.boxOffsetTop - maxOffset) * (1 - this.speed) | 0; 184 185 if (imageHeightMin * this.aspectRatio >= this.boxWidth) { 186 this.imageWidth = imageHeightMin * this.aspectRatio | 0; 187 this.imageHeight = imageHeightMin; 188 this.offsetBaseTop = imageOffsetMin; 189 190 var margin = this.imageWidth - this.boxWidth; 191 192 if (this.positionX == 'left') { 193 this.offsetLeft = 0; 194 } else if (this.positionX == 'right') { 195 this.offsetLeft = - margin; 196 } else if (!isNaN(this.positionX)) { 197 this.offsetLeft = Math.max(this.positionX, - margin); 198 } else { 199 this.offsetLeft = - margin / 2 | 0; 200 } 201 } else { 202 this.imageWidth = this.boxWidth; 203 this.imageHeight = this.boxWidth / this.aspectRatio | 0; 204 this.offsetLeft = 0; 205 206 var margin = this.imageHeight - imageHeightMin; 207 208 if (this.positionY == 'top') { 209 this.offsetBaseTop = imageOffsetMin; 210 } else if (this.positionY == 'bottom') { 211 this.offsetBaseTop = imageOffsetMin - margin; 212 } else if (!isNaN(this.positionY)) { 213 this.offsetBaseTop = imageOffsetMin + Math.max(this.positionY, - margin); 214 } else { 215 this.offsetBaseTop = imageOffsetMin - margin / 2 | 0; 216 } 217 } 218 }, 219 220 render: function() { 221 var scrollTop = Parallax.scrollTop; 222 var scrollLeft = Parallax.scrollLeft; 223 var overScroll = this.overScrollFix ? Parallax.overScroll : 0; 224 var scrollBottom = scrollTop + Parallax.winHeight; 225 226 if (this.boxOffsetBottom > scrollTop && this.boxOffsetTop <= scrollBottom) { 227 this.visibility = 'visible'; 228 this.mirrorTop = this.boxOffsetTop - scrollTop; 229 this.mirrorLeft = this.boxOffsetLeft - scrollLeft; 230 this.offsetTop = this.offsetBaseTop - this.mirrorTop * (1 - this.speed); 231 } else { 232 this.visibility = 'hidden'; 233 } 234 235 this.$mirror.css({ 236 transform: 'translate3d('+this.mirrorLeft+'px, '+(this.mirrorTop - overScroll)+'px, 0px)', 237 visibility: this.visibility, 238 height: this.boxHeight, 239 width: this.boxWidth 240 }); 241 242 this.$slider.css({ 243 transform: 'translate3d('+this.offsetLeft+'px, '+this.offsetTop+'px, 0px)', 244 position: 'absolute', 245 height: this.imageHeight, 246 width: this.imageWidth, 247 maxWidth: 'none' 248 }); 249 } 250 }); 251 252 253 // Parallax Static Methods 254 255 $.extend(Parallax, { 256 scrollTop: 0, 257 scrollLeft: 0, 258 winHeight: 0, 259 winWidth: 0, 260 docHeight: 1 << 30, 261 docWidth: 1 << 30, 262 sliders: [], 263 isReady: false, 264 isFresh: false, 265 isBusy: false, 266 267 setup: function() { 268 if (this.isReady) return; 269 270 var $doc = $(document), $win = $(window); 271 272 var loadDimensions = function() { 273 Parallax.winHeight = $win.height(); 274 Parallax.winWidth = $win.width(); 275 Parallax.docHeight = $doc.height(); 276 Parallax.docWidth = $doc.width(); 277 }; 278 279 var loadScrollPosition = function() { 280 var winScrollTop = $win.scrollTop(); 281 var scrollTopMax = Parallax.docHeight - Parallax.winHeight; 282 var scrollLeftMax = Parallax.docWidth - Parallax.winWidth; 283 Parallax.scrollTop = Math.max(0, Math.min(scrollTopMax, winScrollTop)); 284 Parallax.scrollLeft = Math.max(0, Math.min(scrollLeftMax, $win.scrollLeft())); 285 Parallax.overScroll = Math.max(winScrollTop - scrollTopMax, Math.min(winScrollTop, 0)); 286 }; 287 288 $win.on('resize.px.parallax load.px.parallax', function() { 289 loadDimensions(); 290 Parallax.isFresh = false; 291 Parallax.requestRender(); 292 }) 293 .on('scroll.px.parallax load.px.parallax', function() { 294 loadScrollPosition(); 295 Parallax.requestRender(); 296 }); 297 298 loadDimensions(); 299 loadScrollPosition(); 300 301 this.isReady = true; 302 }, 303 304 configure: function(options) { 305 if (typeof options == 'object') { 306 delete options.refresh; 307 delete options.render; 308 $.extend(this.prototype, options); 309 } 310 }, 311 312 refresh: function() { 313 $.each(this.sliders, function(){ this.refresh() }); 314 this.isFresh = true; 315 }, 316 317 render: function() { 318 this.isFresh || this.refresh(); 319 $.each(this.sliders, function(){ this.render() }); 320 }, 321 322 requestRender: function() { 323 var self = this; 324 325 if (!this.isBusy) { 326 this.isBusy = true; 327 window.requestAnimationFrame(function() { 328 self.render(); 329 self.isBusy = false; 330 }); 331 } 332 }, 333 destroy: function(el){ 334 var i, 335 parallaxElement = $(el).data('px.parallax'); 336 parallaxElement.$mirror.remove(); 337 for(i=0; i < this.sliders.length; i+=1){ 338 if(this.sliders[i] == parallaxElement){ 339 this.sliders.splice(i, 1); 340 } 341 } 342 $(el).data('px.parallax', false); 343 if(this.sliders.length === 0){ 344 $(window).off('scroll.px.parallax resize.px.parallax load.px.parallax'); 345 this.isReady = false; 346 Parallax.isSetup = false; 347 } 348 } 349 }); 350 351 352 // Parallax Plugin Definition 353 354 function Plugin(option) { 355 return this.each(function () { 356 var $this = $(this); 357 var options = typeof option == 'object' && option; 358 359 if (this == window || this == document || $this.is('body')) { 360 Parallax.configure(options); 361 } 362 else if (!$this.data('px.parallax')) { 363 options = $.extend({}, $this.data(), options); 364 $this.data('px.parallax', new Parallax(this, options)); 365 } 366 else if (typeof option == 'object') 367 { 368 $.extend($this.data('px.parallax'), options); 369 } 370 if (typeof option == 'string') { 371 if(option == 'destroy'){ 372 Parallax['destroy'](this); 373 }else{ 374 Parallax[option](); 375 } 376 } 377 }) 378 }; 379 380 var old = $.fn.parallax; 381 382 $.fn.parallax = Plugin; 383 $.fn.parallax.Constructor = Parallax; 384 385 386 // Parallax No Conflict 387 388 $.fn.parallax.noConflict = function () { 389 $.fn.parallax = old; 390 return this; 391 }; 392 393 394 // Parallax Data-API 395 396 $(document).on('ready.px.parallax.data-api', function () { 397 $('[data-parallax="scroll"]').parallax(); 398 }); 399 400}(jQuery, window, document));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.