/    Sign up×
Community /Pin to ProfileBookmark

3 DIV’s transition

Without using jQuery.

I have 3 DIVs. two hidden when using display or collapse when using visibility and one showing.

Via JS I want to display one and hide the other two. Easy.

But how can I make one fade out and the other fade in? make it look like a smooth transition

to post a comment
CSSJavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJan 01.2021 — You can animate opacity by CSS transition:

https://developer.mozilla.org/en-US/docs/Web/CSS/transition
Copy linkTweet thisAlerts:
@kiwisauthorJan 01.2021 — Tried that, but the DIV's all hold their place. So when the 3rd is shown it's "down the page" a lot because the 2 previous ones wit opacity set to 0 still hold their place on the page.

Or is there a way to overcome that?
Copy linkTweet thisAlerts:
@SempervivumJan 02.2021 — I suspect that you intend to implement a cross fade effect, i. e. the div's take the same place and when the opacity changes one is being hidden and the other becomes visible? In this case you need to place one div by absolute positioning above the other.

Demo:

https://jsfiddle.net/Sempervivum/dcrzt6bu/

Feel free to modify it that way that the fading is controlling by javascript instead of CSS hover.
Copy linkTweet thisAlerts:
@VITSUSAJan 02.2021 — @kiwis80#1626364 Can you please share the reference link to understand the exact requirement?
×

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 5.8,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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