Can I use javascript to force the browser to “flush” any pending layout changes?

前端 未结 4 1466
庸人自扰
庸人自扰 2020-12-11 04:01

I have a library that build UI using Javascript, and because of the dynamic content involved I sometimes want to put content out to the browser, examine how the layout was c

4条回答
  •  温柔的废话
    2020-12-11 04:42

    We encountered a crazy problem with IE8 (Firefox, Chrome are fine). We use toggleClass('enoMyAddressesHide') on child element.

    .enoMyAddressesHide{display:none}
    

    But the parent(s) div container does not refresh/re-layout its height.

    setTimeout(), read position, read width and height of element do not help. Finally we can find out a working solution:

    jQuery(document).ready(function ($) {
        var RefreshIE8Layout = function () {
            $('.enoAddressBook:first').css('height', 'auto');
            var height = $('.enoAddressBook:first').height();
            $('.enoAddressBook:first').css('height', height);
        };
    
        $(".enoRowAddressInfo .enoRowAddressInfoArea ul li img.enoMyAddresses").click(function () {
            $(this).parent().find(".enoAllInfoInAddressBox,img.enoMyAddresses").toggleClass('enoMyAddressesHide');
    
            RefreshIE8Layout(); // fix IE8 bug, not refresh the DOM dimension after using jQuery to manipulate DOM
        });
    });
    

    It looks stupid, but it works!

提交回复
热议问题