D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home5
/
grandhou
/
www
/
Filename :
parellaxscroll.js
back
Copy
const simpleParallax = (elem, modifier) => { let paras = document.getElementsByClassName(elem); for (let i = 0; i < paras.length; i++) { let para = paras[i]; para.setAttribute( "style", "background-repeat: no-repeat; background-attachment: fixed; " ); const sp = () => { let x = para.getBoundingClientRect().top / modifier; let y = Math.round(x * 100) / 100; para.style.backgroundPosition = "center " + y + "px"; requestAnimationFrame(sp); }; requestAnimationFrame(sp); } }; simpleParallax("para",4); // preload images