1// simple inline image parallax plugin 2;(function($) { 3 // options 4 function inlineImageParallax(options) { 5 this.options = $.extend({ 6 elems: '.parallaxed__item', 7 position: 'top' // top or left 8 }, options); 9 10 this.init(); 11 } 12 13 // prototype 14 inlineImageParallax.prototype = { 15 init: function() { 16 if (this.options.holder) { 17 this.findElements(); 18 this.attachEvents(); 19 this.startParallax(); 20 } 21 }, 22 findElements: function() { 23 this.holder = $(this.options.holder); 24 this.elems = this.holder.find($(this.options.elems)); 25 }, 26 attachEvents: function() { 27 this.bindHandlers(['onWindowChange']); 28 $(window).bind('scroll resize orientationchange', this.onWindowChange); 29 }, 30 onWindowChange: function() { 31 if (this.destroyed) return; 32 this.startParallax(); 33 }, 34 bindHandlers: function(handlersList) { 35 var self = this; 36 $.each(handlersList, function(index, handler) { 37 var origHandler = self[handler]; 38 self[handler] = function() { 39 return origHandler.apply(self, arguments); 40 }; 41 }); 42 }, 43 startParallax: function() { 44 var self = this, 45 winPosY = $(window).scrollTop(), 46 winPosX = $(window).scrollLeft(); 47 48 this.elems.each(function() { 49 var elems = $(this); 50 51 if (elems.css('background-image') !== 'none') { 52 if (self.options.position === 'top') { 53 elems.css({ 54 transform: "translate3d(0, " + winPosY + 'px' + ", 0)" 55 }); 56 } else if (self.options.position === 'left') { 57 elems.css({ 58 transform: "translate3d( " + winPosX + 'px' + ", 0, 0)" 59 }); 60 } 61 } 62 }); 63 }, 64 destroy: function() { 65 var self = this; 66 self.destroyed = true; 67 68 // destroy handler 69 $(window).unbind('scroll resize orientationchange', this.onWindowChange); 70 // remove assigned styles 71 self.elems.css('transform', ''); 72 // remove data 73 this.holder.removeData('inlineImageParallax'); 74 } 75 }; 76 77 // jquery plugin 78 $.fn.inlineImageParallax = function(opt) { 79 return this.each(function() { 80 $(this).data('inlineImageParallax', new inlineImageParallax($.extend(opt, { holder: this }))); 81 }); 82 }; 83})(jQuery);
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.