1jQuery(document).ready(function($){ 2 3 parallax_box = $('section.parallax-box'); 4 if(parallax_box.length > 0){ 5 ParallaxBox(); 6 } 7 8 function ParallaxBox() 9 { 10 var windowSelector = $(window), 11 documentSelector = $(document), 12 documentWidth = documentSelector.width(), 13 windowHeight = windowSelector.outerHeight(), 14 liteMode = false, 15 ieVersion = getInternetExplorerVersion(); 16 17 var ds = document.documentElement; 18 19 if(!device.mobile() && !device.tablet()){ 20 liteMode = false; 21 22 if (ieVersion !=-1 && ieVersion < 9){ 23 liteMode = true; 24 } 25 }else{ 26 liteMode = true; 27 } 28 29 parallax_box.each(function() 30 { 31 parallaxBox($(this)); 32 }); 33 34 function parallaxBox(obj){ 35 36 var obj_bg = obj.find('.parallax-bg'), 37 type = obj_bg.data('parallax-type'), 38 obj_bg_inner, 39 img, 40 originalWidth = 0, 41 originalHeight = 0, 42 img_url = obj_bg.data('img-url'), 43 bufferRatio = obj_bg.data('speed'), 44 parallaxInvert = obj_bg.data('invert'), 45 parallaxType = 'parallax_normal', 46 objHeight = obj.height(), 47 objOffsetTop = obj.offset().top, 48 baseHeight = 0, 49 parallax = true; 50 notResize = false; 51 52 switch (type) { 53 case 'image': 54 loadImg(); 55 56 break 57 58 case 'video': 59 obj_bg_inner = $('.parallax_media', obj_bg); 60 61 if(liteMode) { 62 obj_bg_inner.remove(); 63 loadImg(); 64 } else { 65 loadVideo(); 66 } 67 68 break 69 } 70 71 function loadImg(){ 72 if(img_url){ 73 img = new Image(); 74 img.src = img_url; 75 76 img.onload = function () 77 { 78 originalWidth = img.width; 79 originalHeight = img.height; 80 81 imgBlocksStructure = !liteMode ? "<div class='parallax-img parallax-bg-inner'></div>" : "<img class='parallax-img parallax-bg-inner' src='' alt=''/>"; 82 obj_bg.append(imgBlocksStructure); 83 obj_bg_inner = $('.parallax-img', obj_bg); 84 85 if(!liteMode){ 86 obj_bg_inner.css('background-image', 'url(' + (img_url) + ')'); 87 } else { 88 obj_bg_inner.attr('src', img_url); 89 bufferRatio = 'none'; 90 } 91 92 initParallax(); 93 } 94 } 95 } 96 97 function loadVideo() 98 { 99 var videoElement = obj_bg_inner.get(0); 100 101 videoElement.load(); 102 videoElement.play(); 103 104 originalWidth = videoElement.videoWidth; 105 originalHeight = videoElement.videoHeight; 106 107 if(img_url){ 108 img = new Image(); 109 img.src = img_url; 110 111 img.onload = function () 112 { 113 originalWidth = originalWidth==0 ? img.width : originalWidth; 114 originalHeight = originalHeight==0 ? img.height : originalHeight; 115 objectResize(obj_bg_inner, documentWidth, baseHeight, originalWidth, originalHeight); 116 } 117 } 118 119 videoElement.onloadeddata = function() 120 { 121 originalWidth = videoElement.videoWidth; 122 originalHeight = videoElement.videoHeight; 123 objectResize(obj_bg_inner, documentWidth, baseHeight, originalWidth, originalHeight); 124 } 125 126 initParallax(); 127 } 128 129 function initParallax() 130 { 131 notResize = false;
132 133 if(!parallaxInvert){ 134 parallaxType = 'parallax_normal'; 135 } else { 136 parallaxType = 'parallax_invert'; 137 } 138 139 switch (bufferRatio) { 140 case 'low': 141 bufferRatio = 3; 142 143 break 144 145 case 'normal': 146 bufferRatio = 2.25; 147 148 break 149 150 case 'hight': 151 bufferRatio = 1.5; 152 153 break 154 155 case 'fixed': 156 if(ieVersion != -1 || getSafari()){ 157 if(type != 'video'){ 158 parallax = false; 159 notResize = true; 160 obj_bg_inner.css({backgroundAttachment:'fixed', width:'100%', height:'100%'}); 161 } else { 162 parallaxType = 'parallax_normal'; 163 bufferRatio = 2.25; 164 } 165 } else { 166 parallaxType = 'parallax_fixes'; 167 bufferRatio = 1; 168 } 169 170 break 171 172 case 'none': 173 parallax = false; 174 parallaxType = 'parallax_none'; 175 176 break 177 178 default: 179 bufferRatio = 2.25; 180 181 if(bufferRatio > 5) bufferRatio = 5; 182 if(bufferRatio <= 1) { 183 if($.browser.msie){ 184 parallax = false; 185 obj_bg_inner.css({backgroundAttachment:'fixed'}); 186 } else { 187 parallaxType = 'parallax_fixes'; 188 bufferRatio = 1; 189 } 190 } 191 192 break 193 } 194 195 windowSelector.resize(parallaxObjResize); 196 parallaxObjResize(); 197 198 if(!liteMode) windowSelector.scroll(parallaxMove); 199 } 200 201 function parallaxObjResize() 202 { 203 documentWidth = documentSelector.width(); 204 windowHeight = windowSelector.outerHeight(); 205 206 objHeight = obj.height(); 207 208 obj_bg.width(documentWidth); 209 obj_bg.css({'width' : documentWidth, 'margin-left' : Math.floor(documentWidth*-0.5), 'left' : '50%'}); 210 211 if(!notResize){ 212 baseHeight = getBaseHeight(parallaxType, objHeight, bufferRatio); 213 objectResize(obj_bg_inner, documentWidth, baseHeight, originalWidth, originalHeight); 214 } 215 216 if(!liteMode) parallaxMove(); 217 } 218 function parallaxMove() 219 { 220 if(parallax && !liteMode){ 221 222 var documentScrollTop, 223 startScrollTop, 224 endScrollTop; 225 226 objOffsetTop = obj.offset().top; 227 documentScrollTop = documentSelector.scrollTop(); 228 229 startScrollTop = documentScrollTop + windowHeight; 230 endScrollTop = documentScrollTop - objHeight; 231 232 if((startScrollTop > objOffsetTop) && (endScrollTop < objOffsetTop)){ 233 234 y = documentScrollTop - objOffsetTop; 235 236 if(!parallaxInvert) { 237 newPositionTop = parseInt(y / bufferRatio); 238 } else { 239 newPositionTop = -parseInt(y / bufferRatio) - parseInt(windowHeight / bufferRatio) 240 } 241 242 obj_bg_inner.css({ top: newPositionTop + 'px' }); 243 } 244 } 245 } 246 } 247 248 function objectResize(obj, baseWidth, baseHeight, originalWidth, originalHeight ) 249 { 250 var imageRatio, 251 originalWidth, 252 originalHeight, 253 newImgWidth, 254 newImgHeight, 255 newImgTop, 256 newImgLeft; 257 258 imageRatio = originalHeight/originalWidth; 259 containerRatio = baseHeight/baseWidth; 260 261 if(containerRatio > imageRatio){ 262 newImgHeight = baseHeight; 263 newImgWidth = Math.round( (newImgHeight*originalWidth) / originalHeight ); 264 }else{ 265 newImgWidth = baseWidth; 266 newImgHeight = Math.round( (newImgWidth*originalHeight) / originalWidth ); 267 } 268 269 newImgLeft=-(newImgWidth-baseWidth)*.5; 270 newImgTop= -(newImgHeight-baseHeight)*.5; 271 272 obj.css({width: newImgWidth, height: newImgHeight, marginTop: newImgTop, marginLeft: newImgLeft}); 273 } 274 275 function getBaseHeight(parallaxType, objHeight, bufferRatio) 276 { 277 var newBaseHeight = 0; 278 279 switch (parallaxType) { 280 case 'parallax_normal': 281 newBaseHeight = objHeight + parseInt((windowHeight - objHeight)/bufferRatio); 282 break 283 284 case 'parallax_invert': 285 newBaseHeight = objHeight + parseInt((windowHeight + objHeight)/bufferRatio); 286 break 287 288 case 'parallax_fixes': 289 newBaseHeight = windowHeight; 290 break 291 292 case 'parallax_none': 293 newBaseHeight = objHeight; 294 break 295 } 296 297 return newBaseHeight; 298 } 299 300 function getInternetExplorerVersion() 301 { 302 var rv = -1; 303 if (navigator.appName == 'Microsoft Internet Explorer') 304 { 305 var ua = navigator.userAgent; 306 var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); 307 if (re.exec(ua) != null) 308 rv = parseFloat( RegExp.$1 ); 309 } 310 else if (navigator.appName == 'Netscape') 311 { 312 var ua = navigator.userAgent; 313 var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})"); 314 315 if (re.exec(ua) != null) 316 rv = parseFloat( RegExp.$1 ); 317 } 318 319 return rv; 320 } 321 function getSafari(){ 322 var safari = false;
323 if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) safari = true; 324 return safari; 325 } 326 } 327 328});
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.