Prevent window scrolling after scrolling window div

I have a small div box that has a vertical scrollbar and is inside an html page that also has a vertical scrollbar.

My problem is when the user reaches the end of the small scroll in the DIV window, the ENTIRE html page containing the div field then starts to scroll (provided that the user scrolls by scrolling the mouse and NOT, actually pressing the DIV button the scroll buttons themselves)

Is there a way to prevent the entire html page from scrolling after the user reaches the end of my little scroll in the DIV window? Any help is appreciated! Thank!

I tried this (but it cancels the scroll even for the div field):

if (window.addEventListener)
    /** DOMMouseScroll is for mozilla. */
    window.addEventListener('DOMMouseScroll', handleWheelEvent, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = handleWheelEvent;

function handleWheelEvent(e){
    e.preventDefault();
}
+3
3

, , : P.

window.addEventListener

document.onmousewheel = handleWheelEvent;

, , , ( scroll = false) , reference (.. getElementById(), ).

Idk - , , , : P .

-J

+1

handleWheelEvent srcElement e preventDefault(), DIV. :

http://www.webdeveloper.com/forum/archive/index.php/t-158824.html

0

. Google . 1700 , 4 , . , , JSFiddle . , .

MacOSX/Chrome.

http://jsfiddle.net/mF8Pr/

.

  • (: , , )
  • - obj,
  • , 0 < obj.scrollTop < (obj.scrollHeight - obj.clientHeight)
  • check direction of scroll attempt event.originalEvent.deltaY
    • UP == negative
    • DOWN == positive
  • event.preventDefault ()

    $(document).bind('mousewheel', function(e){
      //if($overlay.is(':visible'))
      {
        if(e.target != null && e.target.type != 'textarea')
        {
          e.preventDefault();
        }
        else
        {
          if(e.originalEvent.deltaY < 0 && e.target.scrollTop == 0)
          {
            e.preventDefault(); // already at top
          }
          else if(e.originalEvent.deltaY > 0  && e.target.scrollTop >= 
                 (e.target.scrollHeight - e.target.clientHeight))
          {
            // must use greater than because sometimes 
            // the math is wrong by 1px         
            e.preventDefault(); // already at bottom
          }
        }
      }
    });
    

-Amanda

-1
source

Source: https://habr.com/ru/post/1726650/


All Articles