1(function ($) { 2 'use strict'; 3 4$(function() { 5 ParallaxScroll.init(); 6}); 7 8var ParallaxScroll = { 9 /* PUBLIC VARIABLES */ 10 showLogs: false, 11 round: 1000, 12 13 /* PUBLIC FUNCTIONS */ 14 init: function() { 15 this._log("init"); 16 if (this._inited) { 17 this._log("Already Inited"); 18 this._inited = true; 19 return; 20 } 21 this._requestAnimationFrame = (function(){ 22 return window.requestAnimationFrame || 23 window.webkitRequestAnimationFrame || 24 window.mozRequestAnimationFrame || 25 window.oRequestAnimationFrame || 26 window.msRequestAnimationFrame || 27 function(/* function */ callback, /* DOMElement */ element){ 28 window.setTimeout(callback, 1000 / 60); 29 }; 30 })(); 31 this._onScroll(true); 32 }, 33 34 /* PRIVATE VARIABLES */ 35 _inited: false, 36 _properties: ['x', 'y', 'z', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'scale'], 37 _requestAnimationFrame:null, 38 39 /* PRIVATE FUNCTIONS */ 40 _log: function(message) { 41 if (this.showLogs) console.log("Parallax Scroll / " + message); 42 }, 43 _onScroll: function(noSmooth) { 44 var scroll = $(document).scrollTop(); 45 var windowHeight = $(window).height(); 46 this._log("onScroll " + scroll); 47 $("[data-parallax]").each($.proxy(function(index, el) { 48 var $el = $(el); 49 var properties = []; 50 var applyProperties = false; 51 var style = $el.data("style"); 52 if (style == undefined) { 53 style = $el.attr("style") || ""; 54 $el.data("style", style); 55 } 56 var datas = [$el.data("parallax")]; 57 var iData; 58 for(iData = 2; ; iData++) { 59 if($el.data("parallax"+iData)) { 60 datas.push($el.data("parallax-"+iData)); 61 } 62 else { 63 break; 64 } 65 } 66 var datasLength = datas.length; 67 for(iData = 0; iData < datasLength; iData ++) { 68 var data = datas[iData]; 69 var scrollFrom = data["from-scroll"]; 70 if (scrollFrom == undefined) scrollFrom = Math.max(0, $(el).offset().top - windowHeight); 71 scrollFrom = scrollFrom | 0; 72 var scrollDistance = data["distance"]; 73 var scrollTo = data["to-scroll"]; 74 if (scrollDistance == undefined && scrollTo == undefined) scrollDistance = windowHeight; 75 scrollDistance = Math.max(scrollDistance | 0, 1); 76 var easing = data["easing"]; 77 var easingReturn = data["easing-return"]; 78 if (easing == undefined || !$.easing|| !$.easing[easing]) easing = null; 79 if (easingReturn == undefined || !$.easing|| !$.easing[easingReturn]) easingReturn = easing; 80 if (easing) { 81 var totalTime = data["duration"]; 82 if (totalTime == undefined) totalTime = scrollDistance; 83 totalTime = Math.max(totalTime | 0, 1); 84 var totalTimeReturn = data["duration-return"]; 85 if (totalTimeReturn == undefined) totalTimeReturn = totalTime; 86 scrollDistance = 1; 87 var currentTime = $el.data("current-time"); 88 if(currentTime == undefined) currentTime = 0; 89 } 90 if (scrollTo == undefined) scrollTo = scrollFrom + scrollDistance; 91 scrollTo = scrollTo | 0; 92 var smoothness = data["smoothness"]; 93 if (smoothness == undefined) smoothness = 30; 94 smoothness = smoothness | 0; 95 if (noSmooth || smoothness == 0) smoothness = 1; 96 smoothness = smoothness | 0; 97 var scrollCurrent = scroll; 98 scrollCurrent = Math.max(scrollCurrent, scrollFrom); 99 scrollCurrent = Math.min(scrollCurrent, scrollTo); 100 if(easing) { 101 if($el.data("sens") == undefined) $el.data("sens", "back"); 102 if(scrollCurrent>scrollFrom) { 103 if($el.data("sens") == "back") { 104 currentTime = 1; 105 $el.data("sens", "go"); 106 } 107 else { 108 currentTime++; 109 } 110 } 111 if(scrollCurrent<scrollTo) { 112 if($el.data("sens") == "go") { 113 currentTime = 1; 114 $el.data("sens", "back"); 115 } 116 else { 117 currentTime++; 118 } 119 } 120 if(noSmooth) currentTime = totalTime; 121 $el.data("current-time", currentTime); 122 } 123 this._properties.map($.proxy(function(prop) { 124 var defaultProp = 0; 125 var to = data[prop]; 126 if (to == undefined) return; 127 if(prop=="scale" || prop=="scaleX" || prop=="scaleY" || prop=="scaleZ" ) { 128 defaultProp = 1; 129 } 130 else { 131 to = to | 0; 132 } 133 var prev = $el.data("_" + prop); 134 if (prev == undefined) prev = defaultProp; 135 var next = ((to-defaultProp) * ((scrollCurrent - scrollFrom) / (scrollTo - scrollFrom))) + defaultProp; 136 var val = prev + (next - prev) / smoothness; 137 if(easing && currentTime>0 && currentTime<=totalTime) { 138 var from = defaultProp; 139 if($el.data("sens") == "back") { 140 from = to; 141 to = -to; 142 easing = easingReturn; 143 totalTime = totalTimeReturn; 144 } 145 val = $.easing[easing](null, currentTime, from, to, totalTime); 146 }
147 val = Math.ceil(val * this.round) / this.round; 148 if(val==prev&&next==to) val = to; 149 if(!properties[prop]) properties[prop] = 0; 150 properties[prop] += val; 151 if (prev != properties[prop]) { 152 $el.data("_" + prop, properties[prop]); 153 applyProperties = true; 154 } 155 }, this)); 156 } 157 if (applyProperties) { 158 if (properties["z"] != undefined) { 159 var perspective = data["perspective"]; 160 if (perspective == undefined) perspective = 800; 161 var $parent = $el.parent(); 162 if(!$parent.data("style")) $parent.data("style", $parent.attr("style") || ""); 163 $parent.attr("style", "perspective:" + perspective + "px; -webkit-perspective:" + perspective + "px; "+ $parent.data("style")); 164 } 165 if(properties["scaleX"] == undefined) properties["scaleX"] = 1; 166 if(properties["scaleY"] == undefined) properties["scaleY"] = 1; 167 if(properties["scaleZ"] == undefined) properties["scaleZ"] = 1; 168 if (properties["scale"] != undefined) { 169 properties["scaleX"] *= properties["scale"]; 170 properties["scaleY"] *= properties["scale"]; 171 properties["scaleZ"] *= properties["scale"]; 172 } 173 var translate3d = "translate3d(" + (properties["x"] ? properties["x"] : 0) + "px, " + (properties["y"] ? properties["y"] : 0) + "px, " + (properties["z"] ? properties["z"] : 0) + "px)"; 174 var rotate3d = "rotateX(" + (properties["rotateX"] ? properties["rotateX"] : 0) + "deg) rotateY(" + (properties["rotateY"] ? properties["rotateY"] : 0) + "deg) rotateZ(" + (properties["rotateZ"] ? properties["rotateZ"] : 0) + "deg)"; 175 var scale3d = "scaleX(" + properties["scaleX"] + ") scaleY(" + properties["scaleY"] + ") scaleZ(" + properties["scaleZ"] + ")"; 176 var cssTransform = translate3d + " " + rotate3d + " " + scale3d + ";"; 177 this._log(cssTransform); 178 $el.attr("style", "transform:" + cssTransform + " -webkit-transform:" + cssTransform + " " + style); 179 } 180 }, this)); 181 if(window.requestAnimationFrame) { 182 window.requestAnimationFrame($.proxy(this._onScroll, this, false)); 183 } 184 else { 185 this._requestAnimationFrame($.proxy(this._onScroll, this, false)); 186 } 187 } 188}; 189})(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.