Scroll position lost when hiding div

后端 未结 2 686
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 02:33

http://jsfiddle.net/cbp4N/16/

If you show the div. Change the scroll position and then hide and show it agian the scroll position is lost.

am I doing anythi

相关标签:
2条回答
  • 2021-01-19 02:36

    This is normal behaviour because the element is set to the least possible variables to memory when you hide it. If you want to remember scroll position you'll have to store those yourself and then apply the scroll position on showing it.

    Scroll Position of div with "overflow: auto"

    0 讨论(0)
  • 2021-01-19 02:58

    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');
        }
    });
    

    example

    0 讨论(0)
提交回复
热议问题