IE10 reset the scrollbars (position to top-left) for a block (overflow:auto) after {display:none, display:block} sequence

扶醉桌前 提交于 2019-12-06 19:47:28

Your problem will solve if you add the below line into click function

$('#divu').scrollTop($('#divu')[0].scrollHeight);

Working Demo

jQuery

$(document).ready(function(){

    $('#hide').click(function(){
        $('#divu').hide();
    });
    $('#show').click(function(){
        $('#divu').show();
        $('#divu').scrollTop($('#divu')[0].scrollHeight); /*Added this line*/
    });

    $('#divu').scrollTop($('#divu')[0].scrollHeight);
});

I don't know what is the reason of this, but I guess you can store scrollTop value when you hide list and restore it when you show it like this:

$(document).ready(function(){
    var scrollVal; // variable

    $('#hide').click(function(){
        scrollVal = $('#divu').scrollTop();
        $('#divu').hide();
    });
    $('#show').click(function(){
        $('#divu').show();
        $('#divu').scrollTop(scrollVal);
    });

     $('#divu').scrollTop($('#divu')[0].scrollHeight);
});

Or use

$('#divu').css('visibility', 'collapse');
// ...    
$('#divu').css('visibility', 'visible');

Fiddle

Or you can overload jQuery show and hide functions with your custom logic. I think this solution will be much easy and efficient for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!