I have the following html page. Why does alert not working when I scroll the mouse?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(window).scroll(function(){
alert("scrolling");
});
</script>
</head>
<body>
</body>
</html>
EDIT: It works when page has the scroll bar on the right side and when scroll moves the page down. But I want it to work on empty page, for instance.
EDIT2: I have changed document.body to window but have the same problem.
EDIT3: So, i have come to result that I want to catch mouse wheel event
It’s not the body but the window.
However I would put it after the document is ready.
Here’s a working code:
In answer to your edit 3
To catch the mouse wheel event use the jquery mousewheel_plugin see this example
So your code would be