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…

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

Community
  • 1
  • 1
Tanky
  • 51
  • 3

1 Answers1

0

Here it works but the blind effect is kinda ugly with scroll...

$('#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/

Oliboy50
  • 2,661
  • 3
  • 27
  • 36
  • Thanks! Do you think there is a way of preventing the div to scroll before the blind effect? – Tanky Oct 10 '13 at 10:27
  • Yes, don't use 'blind' effect. Use fast or something else. – Oliboy50 Oct 10 '13 at 10:29
  • Do you know a way to make it smoothly scroll back left before the blind effect happens? – Tanky Oct 10 '13 at 11:42
  • You have to set the div overflow to hidden, only works with static height, if your div content is higher than the container, you might want to scroll content with JavaScript, or change to overflow hidden, when blind is triggered and the back to overflow auto when content is exposed. – raphie Jul 22 '17 at 23:15