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

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

    danorton solution didn't work for me. I had some really weird problems where webkit wouldn't draw some elements at all; where text in inputs wasn't updated until onblur; and changing className would not result in a redraw.

    My solution, I accidentally discovered, was to add a empty style element to the body, after the script.

    
    ...
    
    
    ...
    

    That fixed it. How weird is that? Hope this is helpful for someone.

提交回复
热议问题