1var windowHeight = window.innerHeight; 2 3document.addEventListener('resize', function() { 4 windowHeight = window.innerHeight; 5}) 6 7function outerHeight(el) { 8 var height = el.offsetHeight; 9 var style = getComputedStyle(el); 10 11 height += parseInt(style.marginTop) + parseInt(style.marginBottom); 12 return height; 13} 14 15function parallax (el, speedFactor, outerHeight) { 16 var foo = document.querySelectorAll(el); 17 18 var getHeight; 19 var firstTop; 20 var paddingTop = 0; 21 22 //get the starting position of each element to have parallax applied to it 23 foo.forEach(function(subEl){ 24 firstTop = subEl.getBoundingClientRect().top; 25 }); 26 27 if (outerHeight) { 28 getHeight = function(el) { 29 return outerHeight(el); 30 }; 31 } else { 32 getHeight = function(el) { 33 return el.clientHeight; 34 }; 35 } 36 37 // function to be called whenever the window is scrolled or resized 38 function update(){ 39 var pos = window.scrollY; 40 41 foo.forEach(function(subEl){ 42 var element = subEl; 43 var top = element.getBoundingClientRect().top; 44 var height = getHeight(element); 45 46 element.style.top = -(Math.round((firstTop - pos) * speedFactor)) + "px"; 47 }); 48 } 49 document.addEventListener('scroll', update, true) 50 document.addEventListener('resize', update) 51 update() 52}; 53 54parallax(".hero", -0.6);
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.