Friday, December 28, 2012

onscroll

Event handler onscroll (Bubbles: No, Cancelable: No) terjadi ketika isi dari suatu elemen yang mempunyai scrollbar di-scroll.

Berikut contoh meregister event handler onscroll via 'inline model':

<DIV STYLE="width:200px;height:200px;overflow:auto" ONSCROLL="alert('Halo saya event handler')"> <P STYLE="width:400px;height:400px">Scroll...</P> </DIV>

Berikut contoh meregister event handler onscroll via 'traditional model':

<DIV ID="divID" STYLE="width:200px;height:200px;overflow:auto"> <P STYLE="width:400px;height:400px">Scroll...</P> </DIV> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert("Halo saya event handler"); } document.getElementById("divID").onscroll=HandleEvent; </SCRIPT>

Berikut contoh meregister event handler onscroll via DOM:

<DIV ID="divID" STYLE="width:200px;height:200px;overflow:auto"> <P STYLE="width:400px;height:400px">Scroll...</P> </DIV> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert("Halo saya event handler"); } var divElem=document.getElementById("divID"); divElem.addEventListener("scroll", HandleEvent, false); </SCRIPT>