Click wheel fix for mac (safari + firefox)


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // *** inside javascript **
  2. function handleWheel(event) {
  3. var app = document.getElementById('flashSite');
  4. var delta = 0;
  5. if (!event) event = window.event;
  6. if (event.wheelDelta) {
  7. delta = -(event.wheelDelta/60);
  8. } else if (event.detail) {
  9. delta = event.detail;
  10. }
  11. var o = {
  12. x: event.screenX,
  13. y: event.screenY,
  14. delta: delta,
  15. ctrlKey: event.ctrlKey,
  16. altKey: event.altKey,
  17. shiftKey: event.shiftKey
  18. };
  19. if (app && typeof(app.handleWheel) == 'function')
  20. app.handleWheel(o);
  21. }
  22.  
  23. // on page onload
  24. if(!(document.attachEvent)) {
  25. window.addEventListener("DOMMouseScroll", handleWheel, false);
  26. window.addEventListener('mousewheel', handleWheel, false);
  27. document.addEventListener('mousewheel', handleWheel, false);
  28. }
  29.  
  30. // *** inside flash ***
  31. if(ExternalInterface.available){
  32. ExternalInterface.addCallback("handleWheel", handleWheel);
  33. }
  34.  
  35. // method that will be accessed from dispatched javascript events
  36. public function handleWheel(event:Object): void {
  37. var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
  38. event.x, event.y, this,
  39. event.ctrlKey, event.altKey, event.shiftKey,
  40. false, -Number(event.delta));
  41. this.dispatchEvent(mEvent); // where "this" is the documentClass. Can be "stage" too
  42. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.