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

后端 未结 27 2310
我寻月下人不归
我寻月下人不归 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:21

    I came up here because I needed to redraw scrollbars in Chrome after changing its css.

    If someone's having the same problem, I solved it by calling this function:

    //Hack to force scroll redraw
    function scrollReDraw() {
        $('body').css('overflow', 'hidden').height();
        $('body').css('overflow', 'auto');
    }
    

    This method is not the best solution, but it may work with everything, hiding and showing the element that needs to be redraw may solve every problem.

    Here is the fiddle where I used it: http://jsfiddle.net/promatik/wZwJz/18/

提交回复
热议问题