问题
First, play with the navigation menu on this page (left-side): http://bestds.com/TankStorage/
I'm using javascipt to update the dom backgroundColor of these li elements upon click.
Firefox renders the updated DOM elements, but Chrom and Chromium do not render them.
Using Chromium's document inspector, I can clearly see that the li element's background-color has been updated correctly, but they're not being rendered. What's funny, is it will go ahead and render the DOM changes after I hover my my cursor over the unrendered html element in Chrom's document inspector!
How should I fix this?
回答1:
I figured it out. Chrom has a rendering bug.
If you call a window scroll function, immediately after you update some DOM properties, Chrom won't fully render all your DOM modifications.
To fix the problem, I replace this line:
window.scroll(0,docPos);
With this line:
setTimeout('window.scroll(0,' + docPos + ')',1);
This gives Chrom the ability to render the dom changes before the window-scroll-rendering bug can stop it.
来源:https://stackoverflow.com/questions/10924234/chrome-bug-window-scroll-method-intercepts-dom-rendering