Cross fading between three divs in CSS - html

I've been working on cross-fading between three different images for a "twinkling" effect, but discovered I actually need to do this with three different divs so I can use the "background-repeat" property. The problem is I can't seem to figure out how to modify the code to work with divs instead of images.
Here's the code I've been using that works with images:
CSS:
#-webkit-keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#-moz-keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#starrysky img {
position: top left fixed;
width:900px;
}
#starrysky img:nth-child(2) {
opacity: .9;
-webkit-animation: twinkle 1.25s ease-in alternate infinite;
-moz-animation: twinkle 1.25s ease-in alternate infinite;
animation: twinkle 1.25s ease-in alternate infinite;
transition-delay: 2s;
}
#starrysky img:nth-child(3) {
opacity: .9;
-webkit-animation: twinkle 1.75s ease-in alternate infinite;
-moz-animation: twinkle 1.75s ease-in alternate infinite;
animation: twinkle 1.75s ease-in alternate infinite;
transition-delay: 3s;
}
#starrysky img:nth-child(4) {
opacity: .7;
-webkit-animation: twinkle 2.5s ease-in alternate infinite;
-moz-animation: twinkle 2.5s ease-in alternate infinite;
animation: twinkle 2.5s ease-in alternate infinite;
transition-delay: 2s;
}
and HTML:
<div id="starrysky">
<img src="arcticnomoon1.jpg;">
<img src="arcticnomoon2.jpg">
<img src="arcticnomoon3.jpg">
</div>
Any help would be much appreciated! I'm hoping to be able to do this without jQuery, or if I must, very simple jQuery. :\

Well you are on the right track, you're just positioning the images in the #starrysky div a bit wrong :)
Here's an example
#-webkit-keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#-moz-keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#keyframes twinkle {
from { opacity: 0; }
to { opacity: 1; }
}
#starrysky {
position: relative;
width: 300px;
height: 200px;
overflow: hidden;
}
#starrysky img {
position: absolute;
left: 0;
top: 0;
width: 100%;
}
#starrysky img{
opacity: .9;
-webkit-animation: twinkle 1.25s ease-in alternate infinite;
-moz-animation: twinkle 1.25s ease-in alternate infinite;
animation: twinkle 1.25s ease-in alternate infinite;
transition-delay: 2s;
}
#starrysky img:nth-child(2) {
opacity: .9;
-webkit-animation: twinkle 1.75s ease-in alternate infinite;
-moz-animation: twinkle 1.75s ease-in alternate infinite;
animation: twinkle 1.75s ease-in alternate infinite;
transition-delay: 3s;
}
<div id="starrysky">
<img src="http://www.southernhillsanimalhospital.com/sites/site-1450/images/kittens.jpg" />
<img src="http://dreamatico.com/data_images/kitten/kitten-2.jpg" />
</div>

Related

Animation with a delay

I have animation:
#-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#animation1 {
height: 100px;
width: 100px;
background: pink;
opacity: 0;
-webkit-animation: fadein 2s ease-in alternate;
-moz-animation: fadein 2s ease-in alternate;
animation: fadein 2s ease-in alternate;
animation-delay: 2s;
}
<div id="animation1"></div>
I would like to have a hidden element by 2 seconds and show it, but this element disappears after animation. When I remove opacity 0, element is visable earlier than it should. How to do it?
You can use animation-fill-mode: forwards
#-webkit-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#-moz-keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
#animation1 {
height: 100px;
width: 100px;
background: pink;
opacity: 0;
-webkit-animation: fadein 2s ease-in alternate;
-moz-animation: fadein 2s ease-in alternate;
animation: fadein 2s ease-in alternate;
animation-delay: 2s;
animation-fill-mode: forwards;
}
<div id="animation1"></div>

timed display (CSS only) - can we pass duration as part of HTML?

I have the following CSS classes, and HTML code that implement a timed display:
.timedSuccessBox {
color: white;
background: #27ae60;
border-radius: 5px;
padding: 5px;
-moz-animation: inAndOut 5s ease-in forwards;
-webkit-animation: inAndOut 5s ease-in forwards;
animation: inAndOut 5s ease-in forwards;
}
#keyframes inAndOut {
0% {
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<div class='timedSuccessBox'>That worked!</div>
Is it possible to continue only using CSS (no JS) and pass the duration of animation, currently hard coded to 5?
Ideally what I want is, if the invoking HTML code passes a duration, that will be used, else fallback to 5s.
Thanks.
You could override a custom property which is set to 5s by default
:root {
--duration: 5s;
}
.timedSuccessBox {
color: white;
background: #27ae60;
border-radius: 5px;
padding: 5px;
-moz-animation: inAndOut var(--duration) ease-in forwards;
-webkit-animation: inAndOut var(--duration) ease-in forwards;
animation: inAndOut var(--duration) ease-in forwards;
}
#keyframes inAndOut {
0% {
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<div class='timedSuccessBox' style='--duration: 10s'>That worked!</div>
I think you could use that in html:
<div class='timedSuccessBox' style='animation-duration: 10s!important'>That worked!</div>

Is there a way to slowly add letters to text by css? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to display a word (suppose Slow), is there a way to first display 'slow' then by CSS animation add few O's in the middle,
making it from Slow to Sloooooow.
I am using latest chrome so any CSS3/HTML5 features are welcome.
You can consider animating the maximum width of a span like below.
.slow {
display: inline-block;
vertical-align: bottom;
max-width: 0.5rem;
overflow: hidden;
animation: slow 2s ease forwards;
}
#keyframes slow {
from {
max-width: 0.5rem;
}
to {
max-width: 3rem;
}
}
<span>Sl</span><span class="slow">oooooo</span><span>w</span>
You could add all the additional os as <span> elements and then animate them all consecutively using :nth-child to select them one by one:
html, body {
height: 100%;
}
body {
display: flex;
}
h1 {
font-size: 10vw;
margin: auto;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
h1 span {
max-width: 0;
overflow: hidden;
display: inline-block;
vertical-align: bottom;
}
#keyframes in {
from { max-width: 0; opacity: 0; }
25% { max-width: 1em; opacity: 0; }
to { max-width: 1em; opacity: 1; }
}
h1 span {
animation: in 1s;
animation-fill-mode: forwards;
}
h1 span:nth-child(1){ animation-delay: 0s; }
h1 span:nth-child(2){ animation-delay: 1s; }
h1 span:nth-child(3){ animation-delay: 2s; }
h1 span:nth-child(4){ animation-delay: 3s; }
h1 span:nth-child(5){ animation-delay: 4s; }
h1 span:nth-child(6){ animation-delay: 5s; }
h1 span:nth-child(7){ animation-delay: 6s; }
h1 span:nth-child(8){ animation-delay: 7s; }
h1 span:nth-child(9){ animation-delay: 8s; }
<h1>Slo<span>o</span><span>o</span><span>o</span><span>o</span><span>o</span><span>o</span><span>o</span><span>o</span><span>o</span>w</h1>
Just for fun, here's a solution in actual pure CSS (i.e. only requiring a single HTML element), using the content CSS property:
.expanding-slow::before {
content: "Slo";
animation: expand-slow linear 3s both;
}
.expanding-slow::after { content: "w"; }
#keyframes expand-slow {
0% { content: "Slo"; }
20% { content: "Sloo"; }
40% { content: "Slooo"; }
60% { content: "Sloooo"; }
80% { content: "Slooooo"; }
100% { content: "Sloooooo"; }
}
.expanding-slow--smooth::before {
display: inline-block;
content: "Sloooooo";
max-width: 3ch;
overflow: hidden;
vertical-align: text-top;
animation: expand-slow--smooth linear 3s both;
}
.expanding-slow--smooth::after { content: "w"; }
#keyframes expand-slow--smooth {
0% { max-width: 3ch; }
100% { max-width: 8ch; }
}
Using <code>content</code>:
<p class="expanding-slow"></p>
Using <code>max-width</code>:
<p class="expanding-slow--smooth"></p>
Here's a revised version of #DarioSanchezMartinez 's answer that fits a bit closer to your spec.
/* Taken from http://animista.net/play/entrances/fade-in */
#animate-1 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
}
#animate-2 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 1s;
}
#animate-3 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 2s;
}
#animate-4 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 3s;
}
#-webkit-keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
SL<span id="animate-1">o</span><span id="animate-2">o</span><span id="animate-3">o</span><span id="animate-4">o</span>W
Yes!
/* Taken from http://animista.net/play/entrances/fade-in */
#animate-1 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
}
#animate-2 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 1s;
}
#animate-3 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 2s;
}
#animate-4 {
-webkit-animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation: fade-in 1.2s cubic-bezier(0.390, 0.575, 0.565, 1.000) both;
animation-delay: 3s;
}
#-webkit-keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<h1 id="animate-1">S</h1>
<h1 id="animate-2">L</h1>
<h1 id="animate-3">O</h1>
<h1 id="animate-4">W</h1>

Place a Div(s) with Absolute Position on top of an Image so that it won't move on resize.

Is there a way to force animated elements to stay positioned on top of another image?
PROBLEM:
When you resize the browser all of the Animated Elements slide Horizontally and/or Vertically.
Notice the pink square div [as well as the others] move when I resize the screen, I want it to stay in the same place and NOT MOVE.
I've tried to use absolute position on the div, but that doesn't stop
them from moving around on resize. What can I do to keep the elements in a certain spot on the picture?
Please use my fiddle to demonstrate your solution
HTML:
<center>
<div id="wrapper">
<img class="buildingtotal img-responsive" src="http://www.penguins-world.com/wp-content/uploads/emperor_penguin.jpg" >
<div id="animation">
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble toprow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
<div class="bubble bottomrow"> </div>
</div>
<img class="buildingsolo" src="http://i1207.photobucket.com/albums/bb466/audetwebdesign/jsFiddle%20Demos/Puffins.jpg" >
</div>
</center>
CSS:
.toprow{top:0;}
.bottomrow{top:0; margin-top:15%;}
.bubble {
height: 100px;
width: 100px;
position:absolute;
opacity:0;
}
#animation div:nth-of-type(1) {
-webkit-animation: fadein 6s ease-in-out -8s infinite alternate;
-moz-animation: fadein 6s ease-in-out -8s infinite alternate;
animation:fadein 6s ease-in-out -8s infinite alternate;
}
#animation div:nth-of-type(2) {
-webkit-animation: fadein 6s ease-in-out 8s infinite alternate;
-moz-animation: fadein 6s ease-in-out 8s infinite alternate;
animation: fadein 6s ease-in-out 8s infinite alternate;
}
#animation div:nth-of-type(3) {
-webkit-animation: fadein 6s ease-in-out 16s infinite alternate;
-moz-animation: fadein 6s ease-in-out 16s infinite alternate;
animation: fadein 6s ease-in-out 16s infinite alternate;
}
#animation div:nth-of-type(4) {
-webkit-animation: fadein 6s ease-in-out 24s infinite alternate;
-moz-animation: fadein 6s ease-in-out 24s infinite alternate;
animation:fadein 6s ease-in-out 24s infinite alternate;
}
#animation div:nth-of-type(5) {
-webkit-animation: fadein 6s ease-in-out -16s infinite alternate;
-moz-animation: fadein 6s ease-in-out -16s infinite alternate;
animation: fadein 6s ease-in-out -16s infinite alternate;
}
#animation div:nth-of-type(6) {
-webkit-animation: fadein 6s ease-in-out 40s infinite alternate;
-moz-animation: fadein 6s ease-in-out 40s infinite alternate;
animation: fadein 6s ease-in-out 40s infinite alternate;
}
#animation div:nth-of-type(7) {
-webkit-animation: fadein 6s ease-in-out -24s infinite alternate;
-moz-animation: fadein 6s ease-in-out -24s infinite alternate;
animation:fadein 6s ease-in-out -24s infinite alternate;
}
#animation div:nth-of-type(8) {
-webkit-animation: fadein 6s ease-in-out 32s infinite alternate;
-moz-animation: fadein 6s ease-in-out 32s infinite alternate;
animation: fadein 6s ease-in-out 32s infinite alternate;
}
#-webkit-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#-moz-keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
#keyframes fadein {
0% {
opacity: 0;
}
66% {
opacity: 0;
}
76% {
opacity: 1;
}
100% {
opacity: 1;
}
}
.toprow{top:25%; }
.bottomrow{top:0%; }
.bubble:nth-child(1)
{
background: #ff0; left:10%;
}
.bubble:nth-child(2)
{
background: #333; left:30%;
}
.bubble:nth-child(3)
{
background: #f90; left:60%;
}
.bubble:nth-child(4)
{
background: #e43; left:80%;
}
.bubble:nth-child(5)
{
background: #e38; left:10%;
}
.bubble:nth-child(6)
{
background: #338;left:30%;
}
.bubble:nth-child(7)
{
background: #fdd; left:60%;
}
.bubble:nth-child(8)
{
background: #53d; left:80%;
}
}
#media(max-width:630px)
{
#animation {display:none!important;}
.buildingsolo {display:none !important;}
.buildingtotal {display:block !important; top:0!important;}
}
Wrap each image in a div with position:relative;
<div style="position:relative;">
<div style="position:absolute;"><!--box goes here--></div>
<img .../>
</div>
You can also try:
#wrapper { position:relative; display:inline-block; margin:0 auto; }
 
EDIT
Make sure the wrapper is the same width as the image, else it will not work:
<div id="wrapper" style="display:inline-block;">

Imitating a blink tag with CSS3 animations

I really want to make a piece of text blink the old-school style without using javascript or text-decoration.
No transitions, only *blink*, *blink*, *blink*!
This is different from that question because I ask for blinking without continuous transitions, whereas OP of the other questions asks how to replace blinking with continuous transitions
The original Netscape <blink> had an 80% duty cycle. This comes pretty close, although the real <blink> only affects text:
.blink {
animation: blink-animation 1s steps(5, start) infinite;
-webkit-animation: blink-animation 1s steps(5, start) infinite;
}
#keyframes blink-animation {
to {
visibility: hidden;
}
}
#-webkit-keyframes blink-animation {
to {
visibility: hidden;
}
}
This is <span class="blink">blinking</span> text.
You can find more info about Keyframe Animations here.
Let me show you a little trick.
As Arkanciscan said, you can use CSS3 transitions. But his solution looks different from the original tag.
What you really need to do is this:
#keyframes blink {
50% {
opacity: 0.0;
}
}
.blink {
animation: blink 1s step-start 0s infinite;
}
<span class="blink">Blink</span>
JSfiddle Demo
Try this CSS
#keyframes blink {
0% { color: red; }
100% { color: black; }
}
#-webkit-keyframes blink {
0% { color: red; }
100% { color: black; }
}
.blink {
-webkit-animation: blink 1s linear infinite;
-moz-animation: blink 1s linear infinite;
animation: blink 1s linear infinite;
}
This is <span class="blink">blink</span>
​
You need browser/vendor specific prefixes: http://jsfiddle.net/es6e6/1/.
There's actually no need for visibility or opacity - you can simply use color, which has the upside of keeping any "blinking" to the text only:
blink {
display: inline;
color: inherit;
animation: blink 1s steps(1) infinite;
-webkit-animation: blink 1s steps(1) infinite;
}
#keyframes blink { 50% { color: transparent; } }
#-webkit-keyframes blink { 50% { color: transparent; } }
Here is some text, <blink>this text will blink</blink>, this will not.
Fiddle: http://jsfiddle.net/2r8JL/
I'm going to hell for this :
=keyframes($name)
#-webkit-keyframes #{$name}
#content
#-moz-keyframes #{$name}
#content
#-ms-keyframes #{$name}
#content
#keyframes #{$name}
#content
+keyframes(blink)
25%
zoom: 1
opacity: 1
65%
opacity: 1
66%
opacity: 0
100%
opacity: 0
body
font-family: sans-serif
font-size: 4em
background: #222
text-align: center
.blink
color: rgba(#fff, 0.9)
+animation(blink 1s 0s reverse infinite)
+transform(translateZ(0))
.table
display: table
height: 5em
width: 100%
vertical-align: middle
.cell
display: table-cell
width: 100%
height: 100%
vertical-align: middle
http://codepen.io/anon/pen/kaGxC (sass with bourbon)
Another variation
.blink {
-webkit-animation: blink 1s step-end infinite;
animation: blink 1s step-end infinite;
}
#-webkit-keyframes blink { 50% { visibility: hidden; }}
#keyframes blink { 50% { visibility: hidden; }}
This is <span class="blink">blink</span>
If you want smooth blinking text or something a like you can use following code:
.blinking {
-webkit-animation: 1s blink ease infinite;
-moz-animation: 1s blink ease infinite;
-ms-animation: 1s blink ease infinite;
-o-animation: 1s blink ease infinite;
animation: 1s blink ease infinite;
}
#keyframes "blink" {
from,
to {
opacity: 0;
}
50% {
opacity: 1;
}
}
#-moz-keyframes blink {
from,
to {
opacity: 0;
}
50% {
opacity: 1;
}
}
#-webkit-keyframes "blink" {
from,
to {
opacity: 0;
}
50% {
opacity: 1;
}
}
#-ms-keyframes "blink" {
from,
to {
opacity: 0;
}
50% {
opacity: 1;
}
}
#-o-keyframes "blink" {
from,
to {
opacity: 0;
}
50% {
opacity: 1;
}
}
<span class="blinking">I am smoothly blinking</span>
It's working in my case blinking text at 1s interval.
.blink_me {
color:#e91e63;
font-size:140%;
font-weight:bold;
padding:0 20px 0 0;
animation: blinker 1s linear infinite;
}
#keyframes blinker {
50% { opacity: 0.4; }
}
if you want some glow effect use this
#keyframes blink {
50% {
opacity: 0.0;
}
}
#-webkit-keyframes blink {
50% {
opacity: 0.0;
}
}
atom-text-editor::shadow .bracket-matcher .region {
border:none;
background-color: rgba(195,195,255,0.1);
border-bottom: 1px solid rgb(155,155,255);
box-shadow: 0px 0px 9px 4px rgba(155,155,255,0.1);
border-radius: 3px;
animation: blink 2s steps(115, start) infinite;
-webkit-animation: blink 2s steps(115, start) infinite;
}
Please find below solution for your code.
#keyframes blink {
50% {
color: transparent;
}
}
.loader__dot {
animation: 1s blink infinite;
}
.loader__dot:nth-child(2) {
animation-delay: 250ms;
}
.loader__dot:nth-child(3) {
animation-delay: 500ms;
}
Loading <span class="loader__dot">.</span><span class="loader__dot">.</span><span class="loader__dot">.</span>