WheelEvent.preventDefault.scroll.html (3241B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title id='desc'> WheelEvent: wheel - preventDefault() for Scrolling </title> 5 <script type="text/javascript"> 6 var PassTest = function() 7 { 8 document.getElementById("testresult").firstChild.data = "PASS"; 9 } 10 11 var FailTest = function() 12 { 13 document.getElementById("testresult").firstChild.data = "FAIL"; 14 } 15 16 function DisableScrolling() 17 { 18 TARGET.scrollTop = 0; 19 BEFORE = TARGET.scrollTop; 20 DisableScroll = true; 21 } 22 23 function VerifyResult() 24 { 25 AFTER = TARGET.scrollTop; 26 27 if ((true == DisableScroll) && (true == TestResult) && (BEFORE == AFTER)) 28 { 29 PassTest(); 30 } 31 else 32 { 33 FailTest(); 34 } 35 } 36 37 function TestEvent(evt) 38 { 39 if ((true == DisableScroll) && (EVENT == evt.type)) 40 { 41 evt.preventDefault(); 42 TestResult = evt.defaultPrevented; 43 } 44 } 45 46 var EVENT = "wheel"; 47 var BEFORE; 48 var AFTER; 49 var DisableScroll = false; 50 var TestResult = false; 51 52 window.onload = function() 53 { 54 try 55 { 56 TARGET = document.getElementById("target"); 57 TARGET.addEventListener(EVENT, TestEvent, false); 58 } 59 catch(ex) 60 { 61 FailTest(); 62 } 63 } 64 </script> 65 </head> 66 <body> 67 <h3>DOM Events</h3> 68 <h4> 69 Test Description: The typical default action of the wheel event type is to scroll the document/element 70 by the indicated amount. If this event is canceled, the implementation must not scroll document/element. 71 </h4> 72 73 <span id="parent"> 74 <textarea id="target" rows="5" cols="30">TOP TOP TOP TOP TOP TOP TOP Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here Scroll mouse wheel over here END END END END END END END </textarea> 75 </span> 76 <p id="manualsteps"> 77 Steps: 78 <ol> 79 <li> Note: an input device with scroll wheel support (e.g., mouse wheel) is required 80 <li> Make sure the above textarea can be scrolled by scrolling the mouse wheel over it 81 <li> Now, click the button: <button onclick="DisableScrolling()">Disable Scrolling</button> 82 <li> Move the mouse pointer over the above textarea 83 <li> Scroll down the mouse wheel 1 or more units 84 <li> Click the button: <button id="verify" onclick="VerifyResult()">VerifyResult</button> 85 </ol> 86 </p> 87 <p>Test passes if the word "PASS" appears below after following the above steps.</p> 88 <div>Test result: </div> 89 <div id='testresult'>FAIL</div> 90 </body> 91 </html>