How can I force WebKit to redraw/repaint to propagate style changes?

后端 未结 27 2900
我寻月下人不归
我寻月下人不归 2020-11-22 02:04

I have some trivial JavaScript to effect a style change:

sel = document.getElementById(\'my_id\');
sel.className = sel.className.replace(/item-[1-9]-selected         


        
27条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 02:27

    This is fine for JS

    sel.style.display='none';
    sel.offsetHeight; // no need to store this anywhere, the reference is enough
    sel.style.display='block';
    

    But in Jquery, and particularly when you can only use $(document).ready and cannot bind to a the .load event of an object for any particular reason, the following will work.

    You need to get the OUTER(MOST) container of the objects/divs and then remove all its contents into a variable, then re-add it. It will make ALL changes done within the outer container visible.

    $(document).ready(function(){
        applyStyling(object);
        var node = $("div#body div.centerContainer form div.centerHorizontal").parent().parent();
        var content = node.html();
        node.html("");
        node.html(content);
    }
    

提交回复
热议问题