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

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

    This seems related to this: jQuery style not being applied in Safari

    The solution suggested in the first response has worked well for me in these scenarios, namely: apply and remove a dummy class to the body after making the styling changes:

    $('body').addClass('dummyclass').removeClass('dummyclass');
    

    This forces safari to redraw.

提交回复
热议问题