Scrolling to anchors (using jquery) is common – however after the scroll, the user is still able to scroll the entire page with the native scroll bar.
This is what’s needed in nearly every circumstance, however I’d like the user to click a link, get scrolled to the link – the html/body resize (to the divs) size and then the user can just scroll that area, like they’re on a separate page. I’ve accomplished this in FireFox, however in every other browser the code malfunctions. It seems i have something out of order/missing, as broswers like Chrome scrolling is fine, getting div height is fine but when the jquery resizes the html/body, chrome jumps right back up to the top of the page. How could i get around this?
Basically it’s function in FF 5.0 is perfect and i’d like to replicate it across most browsers.
html {
overflow: auto;
}
body {
overflow: hidden;
}
.
function goToByScroll(id){
$('html,body').css('height', '100%');
$('html,body').css('overflow', 'auto');
$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow', function(){
$('html').css('overflow','auto');
$('body').css('overflow','hidden');
$('html,body').css('height', ($("."+id).css('height')));
});
}
j
<div class="links">
<ul class="navigation">
<li><a href="javascript:void(0)" onClick="goToByScroll('linkOne')">linkOne</a>
</li><li>
<a href="javascript:void(0)" onClick="goToByScroll('linkTwo')">linkTwo</a>
</li><li>
<a href="javascript:void(0)" onClick="goToByScroll('linkThree')">linkThree</a>
</li><li>
<a href="javascript:void(0)" onClick="goToByScroll('linkFour')">linkFour</a></li>
</ul>
</div>
Here’s one way to do this by setting the content
<div>s tooverflow:autoand<body>tooverflow:hiddenthen adjust the body’stopoffsetexample: http://jsfiddle.net/pxfunc/BKvae/2/