Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blinking fixed header in site with scrolling animation

So I'm putting a website together which will have a few css3 animations triggered on the scroll event. About halfway through writing the scrolling animations, I'm noticing a lot of blinking on the page's header and other position:fixed elements.

Is there something I can do to minimize this blinking? (Ideally without jQuery)

like image 907
Dom Ramirez Avatar asked Jan 03 '14 14:01

Dom Ramirez


People also ask

How do I add a scroll animation to my website?

The Animation On Scroll is the basic effect of loading and scrolling web pages. You can add it by selecting an Element and then going to the Property Panel. Click on the On Scroll link and check the Animation checkbox.


3 Answers

Use position: sticky; instead of position: fixed;

like image 171
Zia Uddin Muhammad Tarek Avatar answered Sep 23 '22 07:09

Zia Uddin Muhammad Tarek


Well, it looks like this issue is probably isolated to chrome and the speed at which fixed positioned elements render when CSS animations are firing off during scroll.

I wanted to see if this little trick would hardware-accelerate elements that weren't actually the subject of a CSS animation in chrome. Turns out it did. :)

Here's the solution:

.topbar
{
    -webkit-transform: translate3d(0,0,0);
}
like image 35
Dom Ramirez Avatar answered Oct 22 '22 12:10

Dom Ramirez


The transform: translate3d(0,0,0) did not fix the issue in my case for e.g. BS navbar. But instead I stumbled over a different solution which fixed the problem for AOS, Animate.css and also WOW.js. In my case all elements with position: fixed had erratic behaviour when scrolling on mobile (touch devices) through the site.

An approach I found here and here did completely solve the existing problems. Add overflow-x: hidden; to your body a/o section elements that contain the animation.

body { overflow-x: hidden; }

or

section { overflow-x: hidden; } //might be a different container element

Finally my BS navbar is no longer affected by any animations.

like image 2
thex Avatar answered Oct 22 '22 14:10

thex