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
Preserving a Reference to "This" in JavaScript Prototype Functions
Async/Await Always Returns Promise
Selecting Null: What Is the Reason Behind Selectall(Null) in D3
Required Field Validations Not Working in Jquery Popup MVC 4
Are There Constants in JavaScript
Detecting Arrow Key Presses in JavaScript
Render Partial View Using Jquery in ASP.NET MVC
Where Do You Include the Jquery Library From? Google JSAPI? CDN
Define Global Variable with Webpack
How to Configure Cors in a Spring Boot + Spring Security Application
What Techniques Can Be Used to Define a Class in JavaScript, and What Are Their Trade-Offs
Repeat a String in JavaScript a Number of Times
How to JSON.Stringify an Es6 Map
How to Escape Regular Expression Special Characters Using JavaScript
Differencebetween String Primitives and String Objects in JavaScript
Recurring Events in Fullcalendar
How to Loop Through an Array Containing Objects and Access Their Properties