I have a <div id="innerContent">
with overflow-y:scroll;
.
Links to anchors within innerContent are located on parent page, not in the div
.
So far, I have tried anchors and scrollto's to attempt to scroll within the content. They both complete the scroll, but innerContent's height is larger than the browser window, so the entire parent page also scrolls to the anchor when the links are clicked.
Is there a way to do this with javascript, without moving the parent page? I do not have control over the height of the div - this is someone else's design.
This came close... but there isn't an answer here. How to automatic scroll inline div without scrolling the whole page?
Thank you!
This jsfiddle works in Chrome for me. Not tested in other browsers.
Catches the mousewheel event, uses the event data to scroll manually, then cancels the original event. Seems potentially messy for production.
$('#scroll').bind('mousewheel', function(e){
$(this).scrollTop($(this).scrollTop()-e.originalEvent.wheelDeltaY);
//prevent page fom scrolling
return false;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With