<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>scroll 이벤트 사용하기</title> <style> body { height: 600vh; /* vh는 화면의 높이 */ text-align: center; transition: background-color 0.5s; } </style> </head> <body> <h3>스크롤바를 움직이면 배경색이 변함!</h3> <script> document.addEventListener("scroll", function() { let p = window.scrollY; document.body.style.backgroundColor = "rgb(" + p % 255 + "," + (255 - p % 255) + ", 200)"; }); </script> </body> </html>