/    Sign up×
Community /Pin to ProfileBookmark

Transparent background when top of screen only

I have a header bar, when my page loads of the page is scrolled to the top I want the background to be transparent so you can see the background hero image cleanly.

As the user scrolls down I want the header bar to apply my background color.

Is there a way you can do this in CSS or does it need JS ?

Either way any help on how I could do this.

to post a comment
CSSJavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumMar 15.2022 — No, in CSS you cannot reference the scroll position, you will need javascript.

Add an event listener for the scroll event, use rgba for the background color and change the `a` value according to the scroll position.
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...