Reputation: 109
I'm implementing a parallax header on a page. It works pretty well with the Apple TrackPad on Firefox & Safari on Mac OS X. But doesn't work so well on Chrome for Mac nor on any browser in Windows.
This is the jQuery I'm implementing:
/*----------------------------------------------------------------------------*\
* PARALLAX HEADER IMAGE
\*----------------------------------------------------------------------------*/
$(window).scroll( function(){
var scroll = $(window).scrollTop(),
slowScroll = scroll*.85;
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(function() {
$('.no-touch .js--parallax-header').css({ transition: "" });
}, 50));
$('.no-touch .js--parallax-header').css({
transform: "translate3d( 0, " + slowScroll + "px, 0)",
transition: "none" });
});
This is the page I'm trying to implement it on.
It's jittery for one. And with a mouse with a scroll wheel, it's very jumpy. My page does also have a transform effect on it for an off canvas navigation menu so I think I need to work around that.
Squarespace does an excellent job of implementing this same parallax effect. How did they do it?
Any help is greatly appreciated! Thanks!
Upvotes: 2
Views: 1246
Reputation: 7180
Based on how SquareSpace did it:
div.fullscreen-background-image
and section.hero-text
section.hero-text
to be part of the normal scrolltransform:translate3d(0px, 0px, 0px);
of the image inside div.fullscreen-background-image
which is good because transform
is considered a high performance animation!js
, I'd assume they debounced
the scroll event and used requestAnimationFrame()
. Read more about that here!That all being said, you don't have a lot of content to scroll over the lady, so why not consider adding her to the body
as a background-image
and making her background-attachment: fixed;
so that the page scrolls over her? Read more.
Upvotes: 1