隐藏div时滚动位置丢失 [英] Scroll position lost when hiding div
问题描述
如果你显示div。更改滚动位置,然后隐藏并显示滚动位置丢失。
If you show the div. Change the scroll position and then hide and show it agian the scroll position is lost.
我做错了什么或这是一个错误。
是否有一种方法可以使用som插件。
am I doing anything wrong or is this a bug. Is there a way round it with som plugins.
/ Anders
感谢您的回答和解决方案。但是如果我隐藏的div是一个外部div而且滚动div在我隐藏的div内深处。有没有一种聪明的方法来解决这个问题。现在我不能在隐藏/显示的回调中设置/保存滚动位置
Thanks for the answers and solutions. But what if the div that I hide is a outer div and the scrolling div is deep inside the div I hide. Is there a smart way to also fix this. Becuse now I cant set/save the scroll position in the callback of the hide/show
推荐答案
Jquery的。如果您将位置保持为数据,则scrollTop()可以正常工作。
Jquery's .scrollTop() works well if you maintain the position as data.
$('#cbxShowHide').click(function(){
if(this.checked) {
$('#block').show('fast',function() {
$(this).scrollTop($(this).data('scroll'));
});
}
else {
$('#block').data('scroll',$('#block').scrollTop());
$('#block').hide('fast');
}
});
这篇关于隐藏div时滚动位置丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!