Animation delay on background image [duplicate] - html

This question already has answers here:
Stopping a CSS3 Animation on last frame
(8 answers)
Closed 4 years ago.
I have finally made my background image fade in when my webpage loads, and now I want the animation to be a little delayed so you are able to se the background color for a moment.
I have tried to use the "animation-delay: 2s;" thing in css, but when the page loads, the image is already shown and the animation just starts after 2 seconds. This means that the image is shown, then disappears and then do the animation. I then tried to set the image to "opacity: 0;", but then problem just turns around. So now the image isn't shown to begin with, then the animation tuns, but after that the image disappears again
html:
<div class="imageThing">
</div>
css:
/* attempt 1 */
.imageThing {
background: #fff url('image') 0px 0px no-repeat ;
background-size: 100vw 30.15vw;
-webkit-animation: fadein 3s; /* Safari and Chrome */
-moz-animation: fadein 3s; /* Firefox */
-ms-animation: fadein 3s; /* Internet Explorer */
-o-animation: fadein 3s; /* Opera */
animation: fadein 3s;
animation-delay: 2s;
height: 30.15vw;
width: 100vw;
position: absolute; top: 0px; left: 0px;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari and Chrome */
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}​
/* Opera */
#-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}​
/* attempt 2 */
.imageThing {
background: #fff url('image') 0px 0px no-repeat ;
opacity: 0;
background-size: 100vw 30.15vw;
-webkit-animation: fadein 3s; /* Safari and Chrome */
-moz-animation: fadein 3s; /* Firefox */
-ms-animation: fadein 3s; /* Internet Explorer */
-o-animation: fadein 3s; /* Opera */
animation: fadein 3s;
animation-delay: 2s;
height: 30.15vw;
width: 100vw;
position: absolute; top: 0px; left: 0px;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari and Chrome */
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}​
/* Opera */
#-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}​
I need the image to be invisible until a number of seconds after the page loads until the animation begins, and then stay visible. I hobe you can help me :)

You can add animation-fill-mode: both to hold the animation before and after.
.imageThing {
animation-fill-mode: both;
}

Related

Is there a way to do fade in scroll animations by using CSS or HTML only and no Javascript?

I want to have my website where whenever someone scrolls down, a picture or text will fade in up. I´ve been trying to find a way to accomplish this only using CSS or HTML as my website creator doesn't use any other language besides CSS or HTML. Is there some code that I could use to accomplish this?
Yes, you can do this. It's a lot easier with JQuery, but CSS will still work.
<text id="my-text">I hope this helps</text>
<style>
#my-text {
font-size: 20px;
text-align: center;
-webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s; /* Firefox < 16 */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera < 12.1 */
animation: fadein 2s;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
#-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
</style>
I hope this helps! This would work with images and text.
Test this: https://www.w3schools.com/code/tryit.asp?filename=GCR2PD73HDF7

fading image over background image

Building a quick website. Ideally, I want it to look similar to this:
http://imgur.com/a/NVVEv
Where, the hawaii background image is faded in at the start (and stays faded with an opacity of 0.2) & the rectangle in the middle fades in with the title and buttons but displays fully after the background image.
They'd be two seperate images (background #1 and rectangle #2) - how would I'd be best to do this with HTML/CSS? I have the background image working but the rectangle doesn't fade in and show. I'd like to have the buttons also link to pages (unsure how to do this)
Also having trouble finding the best way to resize my page to fit with the browser? I know it's alt tags but I can't remember the exact code needed.
I'm a noob and having trouble finding sufficient code to fulfil my request.
Cheers
CODE BELOW:
HTML:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
<link href="background.css" rel="stylesheet" type="text/css">
</head>
<body>
<img src = "bkgd.jpg" alt=""/>
<img src="backdrop.png" width="1920" height="1080" alt=""/>
</body>
</html>
CSS:
#charset "UTF-8";
/* CSS Document */
html, body {
height: 100%;
margin: 0;
padding: 0;
background-size: auto;
}
img {
opacity: 0.5;
background-repeat: no-repeat;
background-position: center;
margin-right: auto;
margin-left: auto;
background-attachment: fixed;
/*Fade In Animation*/
-webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 2s; /* Firefox < 16 */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera < 12.1 */
animation: fadein 2s;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 0.5; }
}
/* Firefox < 16 */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 0.5; }
}
/* Safari, Chrome and Opera > 12.1 */
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 0.5; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 0.5; }
}
/* Opera < 12.1 */
#-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 0.5; }
}
}
Try this. I have added sample images. The first image is set as body background and the fading image is set as a div background.
To place the fading image in the middle of the page, use
display: flex;
justify-content: center;
align-items: center;
To make the background image fit to screen width, use
width: 100vw;
height: 100vh;
/* Body Margin*/
body {
margin: 0;
}
/* Background Div*/
.background {
position: relative;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
}
/* Background Div: after*/
.background:after {
position: absolute;
width: 100vw;
height: 100vh;
content: '';
background-image: url("https://www.ncl.com/sites/default/files/DestinationGalleries.Hawaii.SnorkelingBay900x400.jpg");
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-color: #999;
-webkit-animation: fadein 10s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 10s;
/* Firefox < 16 */
-ms-animation: fadein 10s;
/* Internet Explorer */
-o-animation: fadein 10s;
/* Opera < 12.1 */
animation: fadein 10s;
/*Fade In Animation*/
}
/* Fade in animations */
#keyframes fadein {
from {
opacity: 0.2;
}
to {
opacity: 1;
}
}
/* Firefox < 16 */
#-moz-keyframes fadein {
from {
opacity: 0.2;
}
to {
opacity: 1;
}
}
/* Safari, Chrome and Opera > 12.1 */
#-webkit-keyframes fadein {
from {
opacity: 0.2;
}
to {
opacity: 1;
}
}
/* Internet Explorer */
#-ms-keyframes fadein {
from {
opacity: 0.2;
}
to {
opacity: 1;
}
}
/* Opera < 12.1 */
#-o-keyframes fadein {
opacity: 0.2;
}
to {
opacity: 1;
}
/* Foregraound div */
.foreground {
margin-top: 20px;
position: relative;
width: 400px;
height: 100px;
background-color: #eaeaea;
padding: 20px;
border: 1px solid #555;
border-radius: 10px;
/*Fade In Animation*/
-webkit-animation: fadein 10s;
/* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 10s;
/* Firefox < 16 */
-ms-animation: fadein 10s;
/* Internet Explorer */
-o-animation: fadein 10s;
/* Opera < 12.1 */
animation: fadein 10s;
z-index: 1;
}
/* Name Tag */
.name-tag {
font-family: 'avenir-light';
text-align: center;
font-size: 24px;
text-transform: uppercase;
}
/* Socail Media List*/
.social-media-list {
list-style: none;
display: flex;
justify-content: space-around;
padding: 0;
}
/* Socail Media Item*/
.social-media-link img {
height: 50px;
width: 50px;
transition: all 0.5s ease;
}
.social-media-link img:hover {
-ms-transform: scale(1.2);
/* IE 9 */
-webkit-transform: scale(1.2);
/* Safari */
transform: scale(1.2);
/* Standard syntax */
}
<section class="background">
<div class="foreground">
<div class="name-tag">lorem ipsum
</div>
<ul class="social-media-list">
<li class="social-media-link">
<img src="https://cdn3.iconfinder.com/data/icons/basicolor-reading-writing/24/077_twitter-128.png">
</li>
<li class="social-media-link">
<img src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/youtube_circle-128.png">
</li>
<li class="social-media-link">
<img src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/linkedin_circle_color-512.png">
</li>
<li class="social-media-link">
<img src="https://cdn2.iconfinder.com/data/icons/black-white-social-media/32/instagram_online_social_media-128.png">
</li>
</ul>
</div>
</section>

Using two buttons on one div, how do you fade in slowly then fade out?

The fadeout animation is not working. I think you can't put two Ids on one div.
How do you get the fadeout to work?
here is the jsFiddle
html
appear
<div id="pop" id="pop_close">
disappear
</div>
CSS
body {
padding: 10em;
}
#pop{
height: 10em;
width: 10em;
background: yellow;
opacity:0;
position: relative;
top: -20px;
z-index: -1;
}
#pop:target {
opacity: 1;
z-index: 1;
-webkit-animation: fadein 1s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadein 1s; /* Firefox < 16 */
-ms-animation: fadein 1s; /* Internet Explorer */
-o-animation: fadein 1s; /* Opera < 12.1 */
animation: fadein 1s;
}
#pop_close:target {
opacity: 0;
z-index: -1;
-webkit-animation: fadeOut 1s; /* Safari, Chrome and Opera > 12.1 */
-moz-animation: fadeOut 1s; /* Firefox < 16 */
-ms-animation: fadeOut 1s; /* Internet Explorer */
-o-animation: fadeOut 1s; /* Opera < 12.1 */
animation: fadeOut 1s;
}
#keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; }
}
/* Firefox < 16 */
#-moz-keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; }
}
/* Safari, Chrome and Opera > 12.1 */
#-webkit-keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; }
}
/* Internet Explorer */
#-ms-keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; }
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox < 16 */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari, Chrome and Opera > 12.1 */
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
here is a working fiddle http://jsfiddle.net/oogley_boogley/wqju9jh6/19/
the css:
#pop{
height: 10em;
width: 10em;
background: yellow;
opacity:0;
position: relative;
top: -20px;
z-index: -1;
transition: opacity 1s; /* key style here, look into -webkit and -moz etc as well */
}
Exactly, you cannot have multiple ID on the same page,
therefore you need to modify the ID to make :target a specific popup:
div[id^=popUp] // means: target DIV element who's ID "starts with".
than in the HTML you simply make the ID unique by adding a number.
div[id^=popUp]{
height: 5em;
width: 5em;
background: yellow;
opacity:0;
position: relative;
top: -20px;
z-index: -1;
transition: opacity 1s;
}
div[id^=popUp]:target {
opacity: 1;
z-index: 1;
}
appear
<div id="popUp1">
disappear
</div>
appear
<div id="popUp2">
disappear
</div>

How to make pure CSS dropdown menu appear with a fade in/slowly

As the title suggest, I'm trying to make a pure CSS drop down menu. The only thing is I cannot get the dropdown to fade in slowly no matter what I've tried.
Here's the JSFiddle
http://jsfiddle.net/UWgCV/
FYI It's not my terrible code, it's from the previous designer who abandoned the project.
Thanks.
edit: I need to accompany this post with code because of the jsfiddlet link, so here is the menu.
<li>EMERGENCY SERVICE |
<ul>
<li> What We Do</li>
<li> How We Are Staffed</li>
<li> Emergency/Referral Procedure </li>
<li> Types of Emergencies</li>
<li> What to Expect On Arrival</li>
</ul>
</li>
You should use CSS3 Animations, although they aren't supported in all browsers such as <=IE9, this is exactly what they were made for. You may want to try jQuery for older browsers.
Workign demo JSFiddle
li:hover > ul {
display: block;
opacity: 0;
z-index: 98;
position: absolute;
-webkit-animation: fadein 2s; /* Safari and Chrome */
-moz-animation: fadein 2s; /* Firefox */
-ms-animation: fadein 2s; /* Internet Explorer */
-o-animation: fadein 2s; /* Opera */
animation: fadein 2s;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Firefox */
#-moz-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Safari and Chrome */
#-webkit-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Internet Explorer */
#-ms-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
/* Opera */
#-o-keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}

Animation on load delay, without showing

I want to fade in my logo at page load. But, I want it to delay. But when I add the delay property, it first shows, and after the delay period it starts the animation. I want the logo to show, after the delay. What am I doing wrong?
Here's the JSFiddle http://jsfiddle.net/c8hx9/
HTML
<div id="show">hello!</div>
CSS
#show {
position: absolute;
left: 50%;
margin-left: -200px;
top: 200px;
margin-bottom: 300px;
animation: fadein 2s;
-moz-animation: fadein 2s;
/* Firefox */
-webkit-animation: fadein 2s;
/* Safari and Chrome */
-o-animation: fadein 2s;
/* Opera */
animation-delay:1s;
-webkit-animation-delay:1s;
}
#keyframes fadein {
from {
opacity:0;
}
to {
opacity:1;
}
}
#-moz-keyframes fadein {
/* Firefox */
from {
opacity:0;
}
to {
opacity:1;
}
}
#-webkit-keyframes fadein {
/* Safari and Chrome */
from {
opacity:0;
}
to {
opacity:1;
}
}
#-o-keyframes fadein {
/* Opera */
from {
opacity:0;
}
to {
opacity: 1;
}
}
Just add opacity on the first statement class:
#show {
opacity:0;
}
And to keep the final of the animation use forwards.
animation-fill-mode: forwards;
Check this Demo http://jsfiddle.net/c8hx9/2/