开发者

Disable mousewheel scroll on swf files?

开发者 https://www.devze.com 2022-12-23 02:18 出处:网络
I am using the scroll in a swf file.. is there anyway to disable the scroll mousewheel on all browsers.. I get it working for IE a开发者_JS百科nd FF but Webkit is not working:

I am using the scroll in a swf file.. is there anyway to disable the scroll mousewheel on all browsers.. I get it working for IE a开发者_JS百科nd FF but Webkit is not working:

$(document).ready(function() {
$("#ebook").hover(
  function () {
    document.onmousewheel = function(){
        return false
    };
    console.log('On');
  },
  function () {
    console.log('Out');
    document.onmousewheel = function() {
        return true;
    }
  }
);

});


With the help of some scripts from the web and JQuery i have assembled the following Javascript solution for the problem and it works fine on all browsers.
Based on: http://adomas.org/javascript-mouse-wheel/
Just disable when the mouse enters the container div and re-enable the mouse onMouseLeave.

jQuery(function(){
  $("#myFlashContainer").mouseenter(
    function () {
      if (window.addEventListener)
      {
        window.removeEventListener('DOMMouseScroll', wheelOn, false);
        window.addEventListener('DOMMouseScroll', wheelOff, false);
      }
      /** IE/Opera. **/
      window.onmousewheel = document.onmousewheel = wheelOff;
    }
  );

  $("#myFlashContainer").mouseleave(
    function () {
      if (window.addEventListener)
      {
        window.removeEventListener('DOMMouseScroll', wheelOff, false);
        window.addEventListener('DOMMouseScroll', wheelOn, false);
      }
      /** IE/Opera. **/
      window.onmousewheel = document.onmousewheel = wheelOn;
    }
  );

  function wheelOff(event)
  {
    var delta = 0;
    if (!event) /* For IE. */
      event = window.event;
    if (event.wheelDelta) { /* IE/Opera. */
      delta = event.wheelDelta/120;
    } else if (event.detail) { /** Mozilla case. */
      /** In Mozilla, sign of delta is different than in IE.
        * Also, delta is multiple of 3.
        */
      // delta = -event.detail/3;
    }

    if (event.preventDefault)
      event.preventDefault();
    event.returnValue = false;
  }

  function wheelOn(event)
  {
    var delta = 0;
    if (!event) /* For IE. */
      event = window.event;
    if (event.wheelDelta) { /* IE/Opera. */
      delta = event.wheelDelta/120;
    } else if (event.detail) { /** Mozilla case. */
      // delta = -event.detail/3;
    }
    if (event.preventDefault)
    {
      //event.preventDefault();
      event.returnValue = true;
    }
    return true;
  }

}); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号