Scroll position lost when hiding div

后端 未结 2 688
隐瞒了意图╮
隐瞒了意图╮ 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: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

提交回复
热议问题