1

I would like to do exactly what's done here: http://jsfiddle.net/cbp4N/17/

$('#cbxShowHide').click(function(){
    if(this.checked) {
        $('#block').show('fast',function() {
            $(this).scrollTop($(this).data('scroll'));
        });
    }
    else {
       $('#block').data('scroll',$('#block').scrollTop());
       $('#block').hide('fast');
    }
});

Found in this post: Scroll position lost when hiding div

But on a div with an horizontal scroll. I've tried that http://jsfiddle.net/cbp4N/233/

$('#button').click(function() {
    if ($('#block').is(':hidden')) {
        $('#block').show("blind");
        $('#block').scrollLeft($('#block').data('scroll'));
    } else {
        $('#block').data('scroll',$('#block').scrollLeft());
        $('#block').hide("blind");
    }
});

But it doesn't work…</p>

We can see the scroll reset before hiding and I would like to prevent that.

4

1 回答 1

0

在这里它可以工作,但滚动的盲目效果有点难看......

$('#button').click(function() {
    if ($('#block').is(':hidden')) {
        $('#block').show("blind", function(){
            $(this).scrollLeft($(this).data('scroll'));
        });
    } else {
        $('#block').data('scroll',$('#block').scrollLeft());
        $('#block').hide("blind");
    }
});

http://jsfiddle.net/cbp4N/234/

于 2013-10-10T10:17:44.600 回答