Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Enhanced Parallax Scrolling</title> <style> body, html { height: 100%; margin: 0; font-family: Arial, sans-serif; overflow-x: hidden; /* Prevent horizontal scroll */ } .parallax { height: 100vh; /* Full height of the viewport */ position: relative; background: url('https://via.placeholder.com/1920x1080') no-repeat center center fixed; background-size: cover; display: flex; justify-content: center; align-items: center; color: white; font-size: 36px; letter-spacing: 1px; } .content { height: 100vh; display: flex; align-items: center; justify-content: center; background: white; color: #333; font-size: 24px; padding: 0 20px; text-align: center; box-sizing: border-box; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; } </style> </head> <body> <div class="content">Scroll down to see the parallax effect!</div> <div class="parallax">Stunning Parallax!</div> <div class="content">Keep scrolling to see more effects.</div> <div class="parallax"></div> <div class="content">You have reached the end. Amazing, right?</div> <script> document.addEventListener('scroll', function() { document.querySelectorAll('.parallax').forEach(function(el) { const factor = 0.5; // Change this for more or less parallax const offset = window.pageYOffset * factor - 300; // Adjusts the starting position of background el.style.backgroundPositionY = offset + 'px'; }); }); </script> </body> </html>