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

后端 未结 27 2295
我寻月下人不归
我寻月下人不归 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条回答
  •  -上瘾入骨i
    2020-11-22 02:36

    A simple solution with jquery:

    $el.html($el.html());
    

    or

    element.innerHTML = element.innerHTML;
    

    Had an SVG that wasn't showing when it was added to the html.

    This can be added after the svg elements are on the screen.

    Better solution is to use:

    document.createElementNS('http://www.w3.org/2000/svg', 'svg');
    

    and with jQuery:

    $(svgDiv).append($(document.createElementNS('http://www.w3.org/2000/svg', 'g'));
    

    this will render correctly on Chrome.

提交回复
热议问题