简体   繁体   English

包装器溢出后,窗口滚动到顶部:通过jQuery隐藏

[英]window scrolls top after wrapper gets overflow:hidden via jQuery

I don't want the window scroll to top after my wrapper gets overflow:hidden via jQuery. 我不希望在包装器溢出后窗口滚动到顶部:通过jQuery隐藏。

$('#shownav').click(function(event) {
    $('#wrapper').toggleClass('noscroll');      
    return false;
});

html: 的HTML:

<div id="shownav"> navigation </div>
<div id="wrapper"> long content </div>

css: CSS:

.noscroll {overflow:hidden;}

the navigation is position:fixed; 导航position:fixed;

the wrapper has position: relative; 包装器的position: relative; and width: 100%; height:100%; width: 100%; height:100%; width: 100%; height:100%;

If I scroll down the long long content and once click the #shownav the content scrolls to the top like scrollTop(0). 如果我向下滚动长内容,然后单击#shownav,则内容将滚动到顶部,如scrollTop(0)。 But I don't what this! 但是我不是这个! What have I missed? 我错过了什么?

Try this: 尝试这个:

$('#shownav').click(function() {
    $('body').toggleClass('noscroll');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM