jQuery or Javascript - how to disable window scroll without overflow:hidden;

后端 未结 8 1900
耶瑟儿~
耶瑟儿~ 2020-12-01 01:16

Hi is it possible to disable window scrolling without using overflow:hidden; when i\'m hover an element?

i tryed :

$(\'.chat-content\').         


        
8条回答
  •  心在旅途
    2020-12-01 01:38

    Following Glens idea, here it goes another possibility. It would allow you to scroll inside the div, but would prevent the body to scroll with it, when the div scroll ends. However, it seems to accumulate too many preventDefault if you scroll too much, and then it creates a lag if you want to scroll up. Does anybody have a suggestion to fix that?

        $(".scrollInsideThisDiv").bind("mouseover",function(){
           var bodyTop = document.body.scrollTop;
           $('body').on({
               'mousewheel': function(e) {
               if (document.body.scrollTop == bodyTop) return;
               e.preventDefault();
               e.stopPropagation();
               }
           });
        });
        $(".scrollInsideThisDiv").bind("mouseleave",function(){
              $('body').unbind("mousewheel");
        });
    

提交回复
热议问题