Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrolling is choppy in chrome when background image is fixed

I'm trying to create a parallax website. But then I have an issue with fixed positioning.

I have several sections , each with a background-attachment:fixed. A position:fixed menu bar on the top with an hidden element in it on top of all sections. A google map 100% with in one of the sections.

Now, the problem is when I scroll the page with animation in google chrome, the scrolling does not go smooth and it flashes several times while scrolling.

I do the scrolling with greensock scrollTo plugin , but that is not the problem as I also tested it with jquery .animate() method. Same result.

I did a research , and found out that chrome has a bug or problem with Fixed positioning ( and sometimes when you put hidden element in it ) Some pages suggested to use these two with the fixed elements :

-webkit-backface-visibility:hidden; 
-webkit-transform: translateZ(0);

I added this to the fixed menu and some of the choppy behavior of it reduced , but still not smooth. If I add this to the sections with background-attachment:fixed elements, the scrolling animation goes smooth but does not act as fixed anymore.

Somebodies says that chrome has problem with large images, some says it has issue with fixed position and somebodies had a solution that did not work for me :D

I uploaded the page : http://www.FarzanMohajerani.com/test/parallax just click anywhere on the page to scroll.

I also created a jsFiddle with the exact same code. But I don't know why it doesn't have the problem in jsFiddle : http://jsfiddle.net/Farzanmc/cRqxT/5/

It would be great if anyone could direct me to the right solution or remind me if I'm doing anything wrong. Thanks

like image 738
Farzanmc Avatar asked Jun 04 '13 11:06

Farzanmc


People also ask

Why is Google Chrome so bad at scrolling?

There are a few problems: Chrome scrolling is okay-ish, but not nearly as good as Microsoft Edge. Chrome is much heavier on resources than Edge; scrolling a .pdf file in Chrome is choppy and not a great experience, especially with the touchpad.

How to fix the background of a page while scrolling?

It can be achieved using a single CSS property - background-attachment. Look at the following demo in which the backgrounds of different sections of a web page are fixed while their contents move on scrolling. The code to create the effect shown in the demo is explained below in steps. The HTML consists of five sections.

What are the pros and cons of using Chrome over edge?

Chrome is much heavier on resources than Edge; scrolling a .pdf file in Chrome is choppy and not a great experience, especially with the touchpad. Scrolling on Facebook is a breeze in Edge, yet a very laggy and choppy experience in Chrome.

What is the parallax effect and scrolling?

Basically, the parallax effect and scrolling is a new website trend whether the background images will moved at different speed than the foreground content when user scrolling down. It’s an attractive effect that can be applied to as many layers as you like.


1 Answers

This solved the issue for me:

-webkit-transform: translate3d(0,0,0);

Adding this rule turns the element into a layer in Chrome, which avoids repainting. In my unique situation the error was caused by browser re-painting.

like image 94
Kevin Leary Avatar answered Sep 20 '22 17:09

Kevin Leary