Scrolling position lost when hiding a div

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

If you show a div. Change the scroll position, and then hide and show it that the scroll position is lost.

Am I doing something wrong or is it a mistake. Is there any way around it with sm modules.

/ Anders

Thanks for the answers and solutions. But what if the div that I am hiding is an external div and the scrollable div is inside the div that I am hiding. Is there any reasonable way to fix this. Now I can not set / save the scroll position in the hide / show callback

+5
source share
2 answers

The JQuery . scrollTop () works well if you save 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

+5
source

, . , , , .

div : auto "

+1

All Articles