Prevent Scrolling of Parent Element When Inner Element Scroll Position Reaches Top/Bottom

Prevent scrolling of parent element when inner element scroll position reaches top/bottom?

It's possible with the use of Brandon Aaron's Mousewheel plugin.

Here's a demo: http://jsbin.com/jivutakama/edit?html,js,output

$(function() {

var toolbox = $('#toolbox'),
height = toolbox.height(),
scrollHeight = toolbox.get(0).scrollHeight;

toolbox.bind('mousewheel', function(e, d) {
if((this.scrollTop === (scrollHeight - height) && d < 0) || (this.scrollTop === 0 && d > 0)) {
e.preventDefault();
}
});

});

How can I prevent the page scrolling when I have scrolled to the bottom of a div inside it?

Check this demo: http://jsfiddle.net/zUGKW/1/

Code:

// bind the mousewheel event
$('.myDiv').bind('mousewheel', function(e) {
// if scroll direction is down and there is nothing more to scroll
if(e.originalEvent.wheelDelta < 0 &&
($(this).scrollTop() + $(this).height()) >= this.scrollHeight) return false;
});


Related Topics



Leave a reply



Submit