Safari 9.0.3 Flickering Issue On Window.scrollTo() Due To A Early Repaint On The Way
I'm experiencing an odd behaviuor in Safari.
On a quite content-rich page, upon specific user action (that requires relayouts and substitutions of elements on the page) I almost rebuild the entire document then I call window.scrollTo()
to move the viewport to a calculated point.
Isolating the problem I found that just before window.scrollTo()
a repaint occurrs (even if the JavaScript is still executing !) then the scroll is performed causing the flicker.
The document is first displayed with the new layout, then -a frame later- displayed (with the new layout) on the new position.
I explored the variuos "Safari flickers" questions (and answers) but none of them covers the issue I'm experiencing.
Answer
The behaviour described is clearly a bug of Safari as repaint must not occurr until JavaScript execution has terminated.
The web page have a solid color background. After some experimenting I found out that using an image as the background instead of a solid color solves the issue.
The main document-sized <div>
has this background CSS property:
background: #eee;
Replacing it with an in-line png (a small square with the same color)
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAABlJREFUeNpifPfuHQMpgHFUw6iG4asBIMAAYmAssRRucYsAAAAASUVORK5CYII=") fixed repeat;
Avoid the spurious repaint and eliminates the flicker.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM