1/* 2 Plugin: PI Parallax 3 Version 1.0.0 4 Author: Pavel Shlykov 5 6 Dual licensed under the MIT and GPL licenses: 7 http://www.opensource.org/licenses/mit-license.php 8 http://www.gnu.org/licenses/gpl.html 9 */ 10 11jQuery(function($) { 12 var $w = $(window), 13 $d = $(document), 14 windowHeight = $w.height(), 15 elements = []; 16 17 $w.resize(function () { 18 windowHeight = $w.height(); 19 }); 20 21 $.fn.parallax = function () { 22 23 $(this).each(function () { 24 25 var $el = $(this), 26 el = { 27 $el: $el, 28 t: $el.offset().top, 29 x: $el.data('parallaxX') || '50%', 30 y: $el.data('parallaxY') || 0, 31 s: $el.data('parallaxSpeed') || 0.5, 32 h: getHeight($el, ($el.data('parallaxOuterHeight') || 1)) 33 }; 34 35 elements.push(el); 36 37 }); 38 39 }; 40 41 $d.on('piBoundChanged', function(){ 42 checkParallaxState(); 43 }); 44 checkParallaxState(); 45 46 function checkParallaxState(){ 47 if(window.piCurrentBound == 'lg'){ 48 enableParallax(); 49 } else { 50 disableParallax(); 51 } 52 } 53 54 function update() { 55 var scrollTop = $w.scrollTop(); 56 57 for (var i = 0; i < elements.length; i++) { 58 var o = elements[i]; 59 o.t = o.$el.offset().top; 60 o.h = getHeight(o.$el, 1); 61 62 if (o.t + o.h > scrollTop && o.t < scrollTop + windowHeight) { 63 o.$el.css('backgroundPosition', o.x + " " + Math.round((o.t - scrollTop + o.y) * o.s) + "px"); 64 } 65 } 66 } 67 68 function getHeight($el, outerHeight) { 69 if (outerHeight) { 70 return $el.outerHeight(true); 71 } else { 72 return $el.height(); 73 } 74 } 75 76 function enableParallax(){ 77 $w.on('scroll.piParallax resize.piParallax', update); 78 update(); 79 } 80 81 function disableParallax(){ 82 $w.off('scroll.piParallax resize.piParallax'); 83 for (var i = 0; i < elements.length; i++) { 84 var o = elements[i]; 85 o.$el.css('backgroundPosition', ''); 86 } 87 } 88 89 90});
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.