↑
Main Page
scroll event
</head>
<body onresize=”alert(‘Resizing’)”>
</body>
</html>
The actual
resize
event occurs at different times depending on the browser being used. In Internet
Explorer and Opera, the
resize
event occurs as soon as a change occurs in the size of the browser. As
soon as the window border is moved one pixel, the event fires. In Mozilla, the
resize
event fires only
after you have stopped resizing the window. Try out the previous example in a few different browsers.
The
resize
event also fires when you maximize or minimize the window.
The scroll event
You may also want to keep track of when a user scrolls the window (or another element) in order to
ensure something remains visible on the screen at all times. By using the
scroll
event, this is easy:
<html>
<head>
<title>OnScroll Example</title>
</head>
<body onscroll=”alert(‘Scrolling’)”>
<p>Try scrolling this window.</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
You can also assign the event handler to the
window.onscroll
property:
<html>
<head>
<title>OnScroll Example</title>
<script type=”text/javascript”>
window.onscroll = function () {
alert(“scrolling”);
}
</script>
</head>
<body>
<p>Try scrolling this window.</p>
<p> </p>
<p> </p>
289
All about Events
12_579088 ch09.qxd 3/28/05 11:39 AM Page 289
Free JavaScript Editor
Ajax Editor
©
→