1var ParallaxScroll = { 2 /* PUBLIC VARIABLES */ 3 showLogs: false, 4 round: 1000, 5 6 /* PUBLIC FUNCTIONS */ 7 init: function() { 8 this._log("init"); 9 if (this._inited) { 10 this._log("Already Inited"); 11 this._inited = true; 12 return; 13 } 14 this._requestAnimationFrame = (function(){ 15 return window.requestAnimationFrame || 16 window.webkitRequestAnimationFrame || 17 window.mozRequestAnimationFrame || 18 window.oRequestAnimationFrame || 19 window.msRequestAnimationFrame || 20 function(/* function */ callback, /* DOMElement */ element){ 21 window.setTimeout(callback, 1000 / 60); 22 }; 23 })(); 24 25 var self = this; 26 $(document).ready(function () { 27 this._inited = false; 28 self._items.each($.proxy(function(index, el) { 29 self._calcCenterPos(el); 30 })); 31 32 33 self._onScroll(true); 34 }); 35 36 }, 37 38 /* PRIVATE VARIABLES */ 39 _items: $('[data-parallax]'), 40 _inited: false, 41 _properties: ['x', 'y', 'z', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'scale'], 42 _requestAnimationFrame: null, 43 _centerPosCss: null, 44 45 /* PRIVATE FUNCTIONS */ 46 _calcCenterPos: function(el) { 47 var $parent = $(el).parent(), 48 yOffset = $(el).data('parallax').y, 49 xOffset = $(el).data('parallax').x; 50 51 // console.log($(el).attr('src')); 52 53 // var img = new Image(); 54 // img.src = $(el).attr('src'); 55 // img.onload = function() { 56 57 58 59 // } 60 61 if(yOffset) { 62 parentHeight = $parent.height(); 63 fullHeight = Math.abs(yOffset) + parentHeight; 64 65 66 67 $(el).css('left', '50%'); 68 $(el).css('min-height', fullHeight); 69 70 elWidth = $(el).width(); 71 offsetLeft = elWidth/2; 72 73 if(yOffset > 0) { 74 $(el).css('bottom', 0); 75 } else { 76 $(el).css('top', 0); 77 } 78 79 $(el).css('margin-left', -(offsetLeft)); 80 } 81 82 if(xOffset) { 83 parentWidth = $parent.width(); 84 fullWidth = Math.abs(xOffset) + parentWidth; 85 86 $(el).css('top', '50%'); 87 $(el).css('min-width', fullWidth); 88 89 elHeight = $(el).height(); 90 offsetTop = elHeight/2; 91 92 if(xOffset < 0) { 93 $(el).css('left', 0); 94 } else { 95 $(el).css('right', 0) 96 } 97 98 $(el).css('margin-top', -(offsetTop)); 99 } 100 101 102 103 104 }, 105 _log: function(message) { 106 if (this.showLogs) console.log("Parallax Scroll / " + message); 107 }, 108 _onScroll: function(noSmooth) { 109 var scroll = $(document).scrollTop(); 110 var windowHeight = $(window).height(); 111 this._log("onScroll " + scroll); 112 this._items.each($.proxy(function(index, el) { 113 var $el = $(el); 114 // var centerOffset = this._calcCenterPos($el); 115 var properties = []; 116 var applyProperties = false; 117 var style = $el.data("style"); 118 if (style == undefined) { 119 style = $el.attr("style") || ""; 120 $el.data("style", style); 121 } 122 var datas = [$el.data("parallax")]; 123 var iData; 124 for(iData = 2; ; iData++) { 125 if($el.data("parallax"+iData)) { 126 datas.push($el.data("parallax-"+iData)); 127 } 128 else { 129 break; 130 } 131 } 132 var datasLength = datas.length; 133 for(iData = 0; iData < datasLength; iData ++) { 134 var data = datas[iData]; 135 var scrollFrom = data["from-scroll"]; 136 if (scrollFrom == undefined) scrollFrom = Math.max(0, $(el).offset().top - windowHeight); 137 scrollFrom = scrollFrom | 0; 138 var scrollDistance = data["distance"]; 139 var scrollTo = data["to-scroll"]; 140 if (scrollDistance == undefined && scrollTo == undefined) scrollDistance = windowHeight; 141 scrollDistance = Math.max(scrollDistance | 0, 1); 142 var easing = data["easing"]; 143 var easingReturn = data["easing-return"]; 144 if (easing == undefined || !$.easing|| !$.easing[easing]) easing = null; 145 if (easingReturn == undefined || !$.easing|| !$.easing[easingReturn]) easingReturn = easing; 146 if (easing) { 147 var totalTime = data["duration"]; 148 if (totalTime == undefined) totalTime = scrollDistance; 149 totalTime = Math.max(totalTime | 0, 1); 150 var totalTimeReturn = data["duration-return"]; 151 if (totalTimeReturn == undefined) totalTimeReturn = totalTime; 152 scrollDistance = 1; 153 var currentTime = $el.data("current-time"); 154 if(currentTime == undefined) currentTime = 0; 155 } 156 if (scrollTo == undefined) scrollTo = scrollFrom + scrollDistance; 157 scrollTo = scrollTo | 0; 158 var smoothness = data["smoothness"]; 159 if (smoothness == undefined) smoothness = 30; 160 smoothness = smoothness | 0; 161 if (noSmooth || smoothness == 0) smoothness = 1; 162 smoothness = smoothness | 0; 163 var scrollCurrent = scroll; 164 scrollCurrent = Math.max(scrollCurrent, scrollFrom); 165 scrollCurrent = Math.min(scrollCurrent, scrollTo); 166 if(easing) { 167 if($el.data("sens") == undefined) $el.data("sens", "back"); 168 if(scrollCurrent>scrollFrom) { 169 if($el.data("sens") == "back") { 170 currentTime = 1; 171 $el.data("sens", "go"); 172 } 173 else { 174 currentTime++; 175 } 176 } 177 if(scrollCurrent<scrollTo) { 178 if($el.data("sens") == "go") { 179 currentTime = 1; 180 $el.data("sens", "back"); 181 } 182 else { 183 currentTime++; 184 } 185 } 186 if(noSmooth) currentTime = totalTime; 187 $el.data("current-time", currentTime); 188 } 189 this._properties.map($.proxy(function(prop) { 190 var defaultProp = 0; 191 var to = data[prop]; 192 if (to == undefined) return; 193 if(prop=="scale" || prop=="scaleX" || prop=="scaleY" || prop=="scaleZ" ) { 194 defaultProp = 1; 195 } 196 else { 197 to = to | 0; 198 } 199 var prev = $el.data("_" + prop); 200 if (prev == undefined) prev = defaultProp; 201 var next = ((to-defaultProp) * ((scrollCurrent - scrollFrom) / (scrollTo - scrollFrom))) + defaultProp; 202 var val = prev + (next - prev) / smoothness; 203 if(easing && currentTime>0 && currentTime<=totalTime) { 204 var from = defaultProp; 205 if($el.data("sens") == "back") { 206 from = to; 207 to = -to; 208 easing = easingReturn; 209 totalTime = totalTimeReturn; 210 } 211 val = $.easing[easing](null, currentTime, from, to, totalTime); 212 }
213 val = Math.ceil(val * this.round) / this.round; 214 if(val==prev&&next==to) val = to; 215 if(!properties[prop]) properties[prop] = 0; 216 properties[prop] += val; 217 if (prev != properties[prop]) { 218 $el.data("_" + prop, properties[prop]); 219 applyProperties = true; 220 } 221 }, this)); 222 } 223 if (applyProperties) { 224 var $parent = $el.parent() 225 if (properties["z"] != undefined) { 226 var perspective = data["perspective"]; 227 if (perspective == undefined) perspective = 800; 228 var $parent = $el.parent(); 229 if(!$parent.data("style")) $parent.data("style", $parent.attr("style") || ""); 230 $parent.attr("style", "perspective:" + perspective + "px; -webkit-perspective:" + perspective + "px; "+ $parent.data("style")); 231 } 232 233 if(properties["scaleX"] == undefined) properties["scaleX"] = 1; 234 if(properties["scaleY"] == undefined) properties["scaleY"] = 1; 235 if(properties["scaleZ"] == undefined) properties["scaleZ"] = 1; 236 if (properties["scale"] != undefined) { 237 properties["scaleX"] *= properties["scale"]; 238 properties["scaleY"] *= properties["scale"]; 239 properties["scaleZ"] *= properties["scale"]; 240 } 241 var translate3d = "translate3d(" + (properties["x"] ? properties["x"] : 0) + "px, " + (properties["y"] ? properties["y"] : 0) + "px, " + (properties["z"] ? properties["z"] : 0) + "px)"; 242 var rotate3d = "rotateX(" + (properties["rotateX"] ? properties["rotateX"] : 0) + "deg) rotateY(" + (properties["rotateY"] ? properties["rotateY"] : 0) + "deg) rotateZ(" + (properties["rotateZ"] ? properties["rotateZ"] : 0) + "deg)"; 243 var scale3d = "scaleX(" + properties["scaleX"] + ") scaleY(" + properties["scaleY"] + ") scaleZ(" + properties["scaleZ"] + ")"; 244 var cssTransform = translate3d + " " + rotate3d + " " + scale3d + ";"; 245 this._log(cssTransform); 246 $el.attr("style", "transform:" + cssTransform + " -webkit-transform:" + cssTransform + " " + style); 247 } 248 }, this)); 249 if(window.requestAnimationFrame) { 250 window.requestAnimationFrame($.proxy(this._onScroll, this, false)); 251 } 252 else { 253 this._requestAnimationFrame($.proxy(this._onScroll, this, false)); 254 } 255 } 256};
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.