Block page internal ScrollBar MouseWheel event bubbling

Source: Internet
Author: User

Use the mouse wheel to trigger a scrolling event on the page's inner element-free scroll bar, which does not trigger a scrolling event for the browser window when the scrollbar reaches the top or bottom of the elements.

Implemented by calling the following function:

function Preventscroll (ID) {var_this =document.getElementById (ID); if(Navigator.userAgent.indexOf ("Firefox") >0) {_this.addeventlistener ('Dommousescroll', Function (e) {_this.scrolltop+ = e.detail >0? -: - -;          E.preventdefault (); },false); }Else{_this.onmousewheel=function (e) {e= e | | Window.Event; _this.scrolltop+ = E.wheeldelta >0? - -: -; return false;      }; }      return  This; }  

Reference: http://www.cnblogs.com/weekend001/archive/2011/05/11/2043474.html

IE9 does not support similar e.returnvalue = False, the corresponding place is changed to return false.

jquery Plugin:

$.fn.extend ({"Preventscroll": function () {//Prevent scrolling$( This). each (function () {var_this = This; if(Navigator.userAgent.indexOf ('Firefox') >=0) {//Firefox_this.addeventlistener ('Dommousescroll', function (e) {E.preventdefault ();},false); } Else{_this.onmousewheel=function (e) {return false;            }; }        })    },    "Areascroll": function () {//zone to prevent bubbling scrolling$( This). each (function () {var_this = This; if(Navigator.userAgent.indexOf ('Firefox') >=0) {//Firefox_this.addeventlistener ('Dommousescroll', Function (e) {_this.scrolltop+ = e.detail >0? -: - -;                E.preventdefault (); }, false); } Else{_this.onmousewheel=function (e) {e= e | | Window.Event; _this.scrolltop+ = E.wheeldelta >0? - -: -; return false;            }; }        })    }});

Block page internal ScrollBar MouseWheel event bubbling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.