Guest User

Untitled

a guest
Jan 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <!-- saved from url=(0014)about:internet -->
  5. <meta http-equiv="X-UA-Compatible" content="IE=10" />
  6. <title> </title>
  7. <style>#scroll { width: 250px; height: 50px; border: 2px solid black; background-color: lightyellow; top: 100px; left: 50px; position:absolute;}</style>
  8. <script language="javascript">
  9. window.onload = function()
  10. {
  11. //adding the event listerner for Mozilla
  12. if(window.addEventListener)
  13. document.addEventListener('DOMMouseScroll', moveObject, false);
  14. //for IE/OPERA etc
  15. document.onmousewheel = moveObject;
  16. }
  17.  
  18. function moveObject(event)
  19. {
  20. var delta = 0;
  21. if (!event)
  22. event = window.event;
  23.  
  24. // normalize the delta
  25. if (event.wheelDelta)
  26. {
  27. // IE and Opera
  28. delta = event.wheelDelta / 60;
  29. }
  30. else if (event.detail)
  31. {
  32. // W3C
  33. delta = -event.detail / 2;
  34. }
  35.  
  36. var currPos=document.getElementById('scroll').offsetTop;
  37. //calculating the next position of the object
  38. currPos=parseInt(currPos)-(delta*10);
  39. //moving the position of the object
  40. document.getElementById('scroll').style.top = currPos+"px";
  41. document.getElementById('scroll').innerHTML = event.wheelDelta + ":" + event.detail + " deltaX: " + event.deltaX;
  42. }
  43. </script>
  44. </head>
  45. <body>
  46. Scroll mouse wheel to move this DIV up and down.
  47. <div id="scroll">Dancing Div</div>
  48. </body>
  49. </html>
Add Comment
Please, Sign In to add comment