javascript - Sticky header that is transparent over main banner? -
i've built client's site on squarespace.
i want create header that:
1) has transparent background when user first arrives on page 2) when user scrolls down, gets background color , remains affixed top of viewport.
thanks!
some info
csstricks have great little example on how (this common solution this).
the basics solution listen scroll event , check when right spot (you can calculate spot programmatically if want). if do, add class header following:
makes header colored wanted be
make header
position: fixed; top: <num>;
orposition: absolute; top: <num>
(i've seen both solutions out in field)!important!
position:absolute
solution less safe, sinceposition: fixed
positions element relative viewport.position:absolute
same only if doesn't have predecessorposition:relative
[for more info, check this link ]
there's experimental css feature position add position: sticky
option. in theory, sticky part [you can see it's experimental experimental badge next on mdn].
the actual solution
https://css-tricks.com/scroll-fix-content/
it includes demo code on codepen.io. notice need scroll view box (class="wrap") , not page itself.
Comments
Post a Comment