Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>scroll / resize (basic throttle)</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>body{height:2000px;} #info{position:fixed;top:8px;left:8px;background:#fff;padding:6px;border:1px solid #ccc;}</style> </head> <body> <div id="info">Scroll and resize the window</div> <script> var t=null; $(window).on("scroll resize", function(){ clearTimeout(t); t = setTimeout(function(){ $("#info").text("scrollY=" + window.scrollY + ", width=" + window.innerWidth); }, 100); }); </script> </body> </html>
Output