简体   繁体   English

滚动到隐藏div的顶部

[英]Scrolling to top of hidden div

I'm trying to scroll a div to the top while it is hidden. 我正试图在隐藏时将div滚动到顶部。 Here's my sample code: 这是我的示例代码:

 function slideUpReset(div) {
    $(div).slideUp('fast', function() {
        $(div).scrollTop(0);
    });
}

But this doesn't work. 但这不起作用。 $(div).scrollTop(0) only works when the div isn't hidden. $(div).scrollTop(0)仅在div未隐藏时有效。 Is there a way I can achieve the effect I want? 有没有办法可以达到我想要的效果?

Try this : 试试这个

if($('#div').prop('display')=='none')
{
$('#div').scroll();
    $("#div").animate({ scrollTop: 1000 }, 2000);
}

All you have to do is wrap the hidden div in another div then scroll to that eg: 你所要做的就是将隐藏的div包装在另一个div中然后滚动到那个例如:

<div id=wrapperdiv> ** your hidden div ** </div>

then update your jquery to scroll to this div 然后更新你的jquery滚动到这个div

 function slideUpReset(div) {
    $(div).slideUp('fast', function() {
        $(div).parent().scrollTop(0);
    });
 }

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

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