CSS Background Auto Play Slider - html

I am aiming to build a background image slider / fade in - fade out javascript and I am stuck on the CSS part.
I have the following code:
<div class="col-md-3">
<div class="feature">
<div class="feature-header slide-0" style="background-image: url('http://placehold.it/125/150')">
<div class="feature-meta">
<i class="fa fa-camera"></i> 3
</div>
</div>
<div class="feature-header slide-1" style="background-image: url('http://placehold.it/125/150')">
<div class="feature-meta">
<i class="fa fa-camera"></i> 3
</div>
</div>
<div class="feature-header slide-2" style="background-image: url('http://placehold.it/125/150')">
<div class="feature-meta">
<i class="fa fa-camera"></i> 3
</div>
</div>
<div class="feature-body">
<h2>JK Simmons</h2>
<p>JK Simmons 'Whiplash' interview</p>
View
</div>
</div>
</div>
What I would like to do here is stack the three divs with background images in such a way that the images can fade in and out showing the user all three images but one at a time.
I need help with the CSS on this, the javascript I think I am ok on.
Thanks

My first thought would be to use CSS animations, along with position: absolute to 'stack' the relevant elements in the correct place. This would give, as a demonstration, the following code (with the &ndash necessary in practice – vendor-prefixed CSS properties and rules omitted, showing only the standards-compliant non-prefixed version in the code here, though with vendor-prefixes in place in the demos):
/*
because there are three elements we show each
element for only the first 33% of the animation
duration: */
#keyframes slideFade {
0 {
opacity: 1;
}
33% {
opacity: 0;
}
}
/*
Setting the default properties: */
.feature-header {
background-repeat: no-repeat;
background-color: #fff;
height: 150px;
width: 150px;
position: absolute;
}
/*
setting a specific background-image for each element
in order to make the transition visible: */
.slide-0 {
background-image: url(http://lorempixel.com/150/150/nightlife);
/*
animation-name ('slideFade'),
animation-duration ('30s' -> 30 seconds),
animation timing function ('linear'),
animation-delay ('20s')
animation-iteration-count ('infinite'):
animation: slideFade 30s linear 20s infinite;
}
.slide-1 {
background-image: url(http://lorempixel.com/150/150/nature);
animation: slideFade 30s linear 10s infinite;
}
.slide-2 {
background-image: url(http://lorempixel.com/150/150/people);
animation: slideFade 30s linear 0 infinite;
}
.feature-body {
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
font-weight: bold;
margin-left: 150px;
}
#-moz-keyframes slideFade {
0 {
opacity: 1;
}
33% {
opacity: 0;
}
}
#-webkit-keyframes slideFade {
0 {
opacity: 1;
}
33% {
opacity: 0;
}
}
#keyframes slideFade {
0 {
opacity: 1;
}
33% {
opacity: 0;
}
}
.feature-header {
background-repeat: no-repeat;
background-color: #fff;
height: 150px;
width: 150px;
position: absolute;
}
.slide-0 {
background-image: url(http://lorempixel.com/150/150/nightlife);
-moz-animation: slideFade 30s linear 20s infinite;
-webkit-animation: slideFade 30s linear 20s infinite;
animation: slideFade 30s linear 20s infinite;
}
.slide-1 {
background-image: url(http://lorempixel.com/150/150/nature);
-moz-animation: slideFade 30s linear 10s infinite;
-webkit-animation: slideFade 30s linear 10s infinite;
animation: slideFade 30s linear 10s infinite;
}
.slide-2 {
background-image: url(http://lorempixel.com/150/150/people);
-moz-animation: slideFade 30s linear 0 infinite;
-webkit-animation: slideFade 30s linear 0 infinite;
animation: slideFade 30s linear 0 infinite;
}
.feature-body {
background-color: rgba(0, 0, 0, 0.7);
color: #fff;
font-weight: bold;
margin-left: 150px;
}
<div class="col-md-3">
<div class="feature">
<div class="feature-header slide-0">
<div class="feature-meta"> <i class="fa fa-camera"></i> 3</div>
</div>
<div class="feature-header slide-1">
<div class="feature-meta"> <i class="fa fa-camera"></i> 3</div>
</div>
<div class="feature-header slide-2">
<div class="feature-meta"> <i class="fa fa-camera"></i> 3</div>
</div>
<div class="feature-body">
<h2>JK Simmons</h2>
<p>JK Simmons 'Whiplash' interview</p> View
</div>
</div>
</div>
External JS Fiddle demo, for experimentation.

Here you go, Erswell.
Online JSfiddle Demo.
Now a days you want this; pure CSS3 animation (no JS).
.slide {
position:absolute;
}
.slide:nth-child(1) {
-webkit-animation: fade 24s 0s infinite;
z-index:40;
}
.slide:nth-child(2) {
-webkit-animation: fade 24s 6s infinite;
z-index:30;
}
.slide:nth-child(3) {
-webkit-animation: fade 24s 12s infinite;
z-index:20;
}
.slide:nth-child(4) {
-webkit-animation: fade 24s 18s infinite;
z-index:10;
}
#-webkit-keyframes fade {
0%{
opacity: 1;
}
15% {
opacity:1;
}
25%{
opacity: 0;
}
90% {
opacity:0;
}
100% {
opacity:1;
}
}

Related

Why does the 3rd image almost skips in this slideshow?

I am trying to create a slideshow in CSS, and it works, BUT...
The 2nd image stays longer than the others, and when it switvhes to the 3rd, it switches right away to the 4th. I don't know what is wrong with my codes, on paper, everything should work fine.
HTML:
<div id="slideshow">
<div id="img1" class="gallery" style="background-image: url('https://i.pinimg.com/originals/7a/d6/80/7ad680c2aeaf6f89496a174c4e0a92db.jpg');"></div>
<div id="img2" class="gallery" style="background-image: url('https://cdn.wallpapersafari.com/69/19/nhvSi4.png');"></div>
<div id="img3" class="gallery" style="background-image: url('https://cdn.idropnews.com/wp-content/uploads/2018/04/26081105/Look-Wide-iPhone-Wallpaper-720x480.jpg');"></div>
<div id="img4" class="gallery" style="background-image: url('https://cdn.idropnews.com/wp-content/uploads/2018/04/23084736/God-is-Real-iPhone-Wallpaper-720x480.jpg');"></div>
<div id="img5" class="gallery" style="background-image: url('https://www.wallpaperuse.com/wallp/15-154924_m.jpg');"></div>
</div>
CSS:
#slideshow{
height: 60%;
}
.gallery{
display: flex;
align-items: center;
height: 60%;
width: 65%;
background-position: center center;
background-size: cover;
}
#img1{
position: absolute;
z-index: 5;
animation: crossfade 25s -0s infinite;
animation-timing-function: ease-in-out;
}
#img2{
position: absolute;
z-index: 4;
animation: crossfade 25s -5s infinite;
animation-timing-function: ease-in-out;
}
#img3{
position: absolute;
z-index: 3;
animation: crossfade 25s -10s infinite;
animation-timing-function: ease-in-out;
}
#img4{
position: absolute;
z-index: 2;
animation: crossfade 25s -15s infinite;
animation-timing-function: ease-in-out;
}
#img5{
position: absolute;
z-index: 1;
animation: crossfade 25s -20s infinite;
animation-timing-function: ease-in-out;
}
#keyframes crossfade{
0% {opacity: 0;}
20% {opacity: 1;}
33% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
The ombination of z-indexes plus the timing seems to be slightly muddling things - for example it takes 5 seconds to bring an image to full opacity, shows it then another 5 seconds to fade it - so there is overlap in timing between non-adjacent images.
This snippet removes the difference in z-index so all slides are equal in that respect (whether or not you need to set z-index at all is outside the scope of this question as we don't know the full surrounding context). It brings an image in over 2 seconds and takes it out over two seconds so the overlap is just with adjacent slides. It also displaces the starts by anothe 2 seconds so at the very beginning a fully opaque image is shown.
#slideshow {
height: 60%;
}
.gallery {
display: flex;
align-items: center;
height: 60%;
width: 65%;
background-position: center center;
background-size: cover;
}
#img1 {
position: absolute;
z-index: 1;
animation: crossfade 25s -2s infinite;
animation-timing-function: ease-in-out;
}
#img2 {
position: absolute;
z-index: 1;
animation: crossfade 25s -7s infinite;
animation-timing-function: ease-in-out;
}
#img3 {
position: absolute;
z-index: 1;
animation: crossfade 25s -12s infinite;
animation-timing-function: ease-in-out;
}
#img4 {
position: absolute;
z-index: 1;
animation: crossfade 25s -17s infinite;
animation-timing-function: ease-in-out;
}
#img5 {
position: absolute;
z-index: 1;
animation: crossfade 25s -22s infinite;
animation-timing-function: ease-in-out;
}
#keyframes crossfade {
0% {
opacity: 0;
}
8% {
opacity: 1;
/* fade in for 2 second */
}
20% {
opacity: 1;
/* stay fully visible for 3 seconds */
}
28% {
opacity: 0;
/* fade out for 2 second */
}
100% {
opacity: 0;
}
}
<div id="slideshow">
<div id="img1" class="gallery" style="background-image: url('https://i.pinimg.com/originals/7a/d6/80/7ad680c2aeaf6f89496a174c4e0a92db.jpg');"></div>
<div id="img2" class="gallery" style="background-image: url('https://cdn.wallpapersafari.com/69/19/nhvSi4.png');"></div>
<div id="img3" class="gallery" style="background-image: url('https://cdn.idropnews.com/wp-content/uploads/2018/04/26081105/Look-Wide-iPhone-Wallpaper-720x480.jpg');"></div>
<div id="img4" class="gallery" style="background-image: url('https://cdn.idropnews.com/wp-content/uploads/2018/04/23084736/God-is-Real-iPhone-Wallpaper-720x480.jpg');"></div>
<div id="img5" class="gallery" style="background-image: url('https://www.wallpaperuse.com/wallp/15-154924_m.jpg');"></div>
</div>

How to Animate Multiple Background images?

I have a background made with 3 separate images i want to add rotate animation to all 3 images. If i animate the number-bg class all 3 images rotates. I want the rotate speed to be different for each image. what is the best approach to do that.
mycode
<style>
body {
height: 100%;
}
.number-bg {
height: 1000px;
background-image: url(https://i.imgur.com/BZrswvf.png),
url(https://i.imgur.com/XJ9zZeA.png),
url(https://i.imgur.com/RJDk9uS.png);
background-repeat: no-repeat;
background-position: center;
}
</style>
<body>
<div class="number-bg">
</div>
</body>
Image:
Check out the code to rotate each image at different speeds.
.number{height: 1000px;
background-repeat: no-repeat;
background-position: center;}
.no-9 {
background-image: url(https://i.imgur.com/BZrswvf.png);
-webkit-animation:spin 3s linear infinite;
-moz-animation:spin 3s linear infinite;
animation:spin 3s linear infinite
}
.no-6 {
background-image: url(https://i.imgur.com/XJ9zZeA.png);
-webkit-animation:spin 6s linear infinite;
-moz-animation:spin 6s linear infinite;
animation:spin 6s linear infinite
}
.no-3 {
background-image: url(https://i.imgur.com/RJDk9uS.png);
-webkit-animation:spin 1s linear infinite;
-moz-animation:spin 1s linear infinite;
animation:spin 1s linear infinite
}
#-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
#-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
#keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); }
<div class="number no-9">
<div class="number no-6">
<div class="number no-3"></div>
</div>
</div>
Change the spin speeds as per your wish.

Add animation to final square in animation

I have this animation in HTML/CSS. The final square in the animation is in green, i'm trying to make it so that each time the green square show up prior to the last time the animation looped. Because in its current state it always shows up at the last square!
HTML:
<div class="loader">
<div class="square" ></div>
<div class="square"></div>
<div class="square last"></div>
<div class="square clear"></div>
<div class="square"></div>
<div class="square last"></div>
<div class="square clear"></div>
<div class="square "></div>
<div class="square last"></div>
</div>
CSS
#-webkit-keyframes enter {
0% {
opacity: 0;
top: -10px;
}
5% {
opacity: 1;
top: 0px;
}
50.9% {
opacity: 1;
top: 0px;
}
55.9% {
opacity: 0;
top: 10px;
}
}
#keyframes enter {
0% {
opacity: 0;
top: -10px;
}
5% {
opacity: 1;
top: 0px;
}
50.9% {
opacity: 1;
top: 0px;
}
55.9% {
opacity: 0;
top: 10px;
}
}
#-moz-keyframes enter {
0% {
opacity: 0;
top: -10px;
}
5% {
opacity: 1;
top: 0px;
}
50.9% {
opacity: 1;
top: 0px;
}
55.9% {
opacity: 0;
top: 10px;
}
}
body {
background: #1fbeca;
}
* {
margin: 0;
}
.loader {
position: absolute;
left: 50%;
top: 50%;
margin-left: -27.5px;
margin-top: -27.5px;
}
.square {
background: white;
width: 15px;
height: 15px;
float: left;
top: -10px;
margin-right: 5px;
margin-top: 5px;
position: relative;
opacity: 0;
-webkit-animation: enter 6s infinite;
animation: enter 6s infinite;
}
.enter {
top: 0px;
opacity: 1;
}
.square:nth-child(1) {
-webkit-animation-delay: 1.8s;
-moz-animation-delay: 1.8s;
animation-delay: 1.8s;
}
.square:nth-child(2) {
-webkit-animation-delay: 2.1s;
-moz-animation-delay: 2.1s;
animation-delay: 2.1s;
}
.square:nth-child(3) {
-webkit-animation-delay: 2.4s;
-moz-animation-delay: 2.4s;
animation-delay: 2.4s;
background: #fdc96f;
}
.square:nth-child(4) {
-webkit-animation-delay: 0.9s;
-moz-animation-delay: 0.9s;
animation-delay: 0.9s;
}
.square:nth-child(5) {
-webkit-animation-delay: 1.2s;
-moz-animation-delay: 1.2s;
animation-delay: 1.2s;
}
.square:nth-child(6) {
-webkit-animation-delay: 1.5s;
-moz-animation-delay: 1.5s;
animation-delay: 1.5s;
}
.square:nth-child(8) {
-webkit-animation-delay: 0.3s;
-moz-animation-delay: 0.3s;
animation-delay: 0.3s;
}
.square:nth-child(9) {
-webkit-animation-delay: 0.6s;
-moz-animation-delay: 0.6s;
animation-delay: 0.6s;
}
.clear {
clear: both;
}
.last {
margin-right: 0;
}
Here's a link: https://codepen.io/dghez/pen/Czuqn
To have the colored square shift position every time the 'enter' animation is run, create a new animation that is 9 times the length of the 'enter' animation.
The reason for this length is that each of the 9 squares needs to be animated for one full run of the 'enter' animation.
9 squares x 6s = 54s.
For 1/9 of this animation (roughly 11%), we change the square's color.
#keyframes squarecolor {
0%, 11.1% {
background-color: #fdc96f;
}
11.2%, 100% {
background-color: white;
}
}
Then, apply this animation to every square, just like the 'enter' animation. Here though, each square should be progressively delayed in increments of 6s.
Here's a link to an updated version of your Codepen.
You can achieve the affect by using a 2nd animation that changes a square at a time to yellow for one entire loop of the animation.
The 2nd animation loops after the 1st animation has run for all 9 squares (6s * 9 = 54s), and each square is delayed to some interval of 6s to line up with the corresponding loop where it should be yellow.
#-webkit-keyframes enter {
0% {
opacity: 0;
top: -10px;
}
5% {
opacity: 1;
top: 0px;
}
50.9% {
opacity: 1;
top: 0px;
}
55.9% {
opacity: 0;
top: 10px;
}
}
#keyframes enter {
0% {
opacity: 0;
top: -10px;
}
5% {
opacity: 1;
top: 0px;
}
50.9% {
opacity: 1;
top: 0px;
}
55.9% {
opacity: 0;
top: 10px;
}
}
#-webkit-keyframes change {
0% {
background: #fdc96f;
}
11.11% { /* one 6s frame in a 54s animation (6/54 = .1111) */
background: #fdc96f;
}
11.12% {
background: white;
}
100% {
background: white;
}
}
#keyframes change {
0% {
background: #fdc96f;
}
11.11% {
background: #fdc96f;
}
11.12% {
background: white;
}
100% {
background: white;
}
}
body {
background: #1fbeca;
}
* {
margin: 0;
}
.loader {
position: absolute;
left: 50%;
top: 50%;
margin-left: -27.5px;
margin-top: -27.5px;
}
.square {
background: white;
width: 15px;
height: 15px;
float: left;
top: -10px;
margin-right: 5px;
margin-top: 5px;
position: relative;
opacity: 0;
}
.enter {
top: 0px;
opacity: 1;
}
.square:nth-child(1) {
-webkit-animation: enter 6s 1.8s infinite, change 54s 12s infinite;
animation: enter 6s 1.8s infinite, change 54s 12s infinite;
}
.square:nth-child(2) {
-webkit-animation: enter 6s 2.1s infinite, change 54s 6s infinite;
animation: enter 6s 2.1s infinite, change 54s 6s infinite;
}
.square:nth-child(3) {
-webkit-animation: enter 6s 2.4s infinite, change 54s infinite;
animation: enter 6s 2.4s infinite, change 54s infinite;
}
.square:nth-child(4) {
-webkit-animation: enter 6s 0.9s infinite, change 54s 30s infinite;
animation: enter 6s 0.9s infinite, change 54s 30s infinite;
}
.square:nth-child(5) {
-webkit-animation: enter 6s 1.2s infinite, change 54s 24s infinite;
animation: enter 6s 1.2s infinite, change 54s 24s infinite;
}
.square:nth-child(6) {
-webkit-animation: enter 6s 1.5s infinite, change 54s 18s infinite;
animation: enter 6s 1.5s infinite, change 54s 18s infinite;
}
.square:nth-child(7) {
-webkit-animation: enter 6s infinite, change 54s 48s infinite;
animation: enter 6s infinite, change 54s 48s infinite;
}
.square:nth-child(8) {
-webkit-animation: enter 6s 0.3s infinite, change 54s 42s infinite;
animation: enter 6s 0.3s infinite, change 54s 42s infinite;
}
.square:nth-child(9) {
-webkit-animation: enter 6s 0.6s infinite, change 54s 36s infinite;
animation: enter 6s 0.6s infinite, change 54s 36s infinite;
}
.clear {
clear: both;
}
.last {
margin-right: 0;
}
<div class="loader">
<div class="square"></div>
<div class="square"></div>
<div class="square last"></div>
<div class="square clear"></div>
<div class="square"></div>
<div class="square last"></div>
<div class="square clear"></div>
<div class="square "></div>
<div class="square last"></div>
</div>
Pen: https://codepen.io/straker/pen/mqdzMw

Why does animation pause on hover work in IE but not Chrome or Edge?

I have the HTML and CSS working to create a scrolling slideshow of 3 images in the same place. I want the animation to pause when I hover over any of the pictures and then just start up again where the animation left off when I stop the hover. The following code works in Internet Explorer, but not in Chrome or Edge. I need it to work in any browser. Can anyone tell me what I am doing wrong?
div.slideshow3 {
position: relative;
height: 300px;
width: 300px;
}
div.slideshow3 figure {
margin: 0;
position: absolute;
}
div.slideshow3:hover figure {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
div.slideshow3 figure:nth-child(1) {
-webkit-animation: xfade3 15s 10s infinite;
animation: xfade3 15s 10s infinite;
}
div.slideshow3 figure:nth-child(2) {
-webkit-animation: xfade3 15s 5s infinite;
animation: xfade3 15s 5s infinite;
}
div.slideshow3 figure:nth-child(3) {
-webkit-animation: xfade3 15s 0s infinite;
animation: xfade3 15s 0s infinite;
}
#-webkit-keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="slideshow3">
<figure>
<img src="http://lorempixel.com/300/300/nature/1" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/2" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/3" style="width:300px; height:300px;">
</figure>
</div>
First of all, the behavior in Chrome and Edge is the correct one and this is probably why Microsoft has corrected the behavior in their latest browser.
The reason why it does not work is very simple. The hover selector (which pauses
the animation) has the same specificity as the other selectors which set the animation and in addition the other selectors are specified after the hover selector in the CSS file. This makes them get precedence over the hover selector at any point of time (even when the hover is on). Because of this, the animation-play-state never gets set to paused and so the animation keeps running.
Let us have a look at the specificity of the selectors one by one:
div.slideshow3:hover figure
The number of ID selectors in the above selector is 0 (so a = 0)
The number of class/attribute/pseudo-class selectors in it is 2 (so b = 2)
The number of type/pseudo-element selectors in it is 2 (so c = 2)
So, its overall specificity is 022.
div.slideshow3 figure:nth-child(1)
The number of ID selectors in the above selector is 0 (so a = 0)
The number of class/attribute/pseudo-class selectors in it is 2 (so b = 2)
The number of type/pseudo-element selectors in it is 2 (so c = 2)
So, the overall specificity for this one is also 022 but it is specified later in the CSS file.
You can read more about CSS Selector Specificity here.
You can fix this issue in two ways and they are as follows:
Move the hover selector below all the animation definition selectors. This makes the hover selector take precedence over the rest and so will pause the animation when the container is hovered on. This is the simplest solution.
div.slideshow3 {
position: relative;
height: 300px;
width: 300px;
}
div.slideshow3 figure {
margin: 0;
position: absolute;
}
div.slideshow3 figure:nth-child(1) {
-webkit-animation: xfade3 15s 10s infinite;
animation: xfade3 15s 10s infinite;
}
div.slideshow3 figure:nth-child(2) {
-webkit-animation: xfade3 15s 5s infinite;
animation: xfade3 15s 5s infinite;
}
div.slideshow3 figure:nth-child(3) {
-webkit-animation: xfade3 15s 0s infinite;
animation: xfade3 15s 0s infinite;
}
div.slideshow3:hover figure {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
#-webkit-keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="slideshow3">
<figure>
<img src="http://lorempixel.com/300/300/nature/1" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/2" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/3" style="width:300px; height:300px;">
</figure>
</div>
The alternate would be to specify your hover selector as div.slideshow3:hover figure:nth-child(n). This means there are 3 class/pseudo-class selectors in the selector and so specificity becomes higher than the others. nth-child(n) basically selects all and so that is not a problem.
div.slideshow3 {
position: relative;
height: 300px;
width: 300px;
}
div.slideshow3 figure {
margin: 0;
position: absolute;
}
div.slideshow3:hover figure:nth-child(n) {
-webkit-animation-play-state: paused;
animation-play-state: paused;
}
div.slideshow3 figure:nth-child(1) {
-webkit-animation: xfade3 15s 10s infinite;
animation: xfade3 15s 10s infinite;
}
div.slideshow3 figure:nth-child(2) {
-webkit-animation: xfade3 15s 5s infinite;
animation: xfade3 15s 5s infinite;
}
div.slideshow3 figure:nth-child(3) {
-webkit-animation: xfade3 15s 0s infinite;
animation: xfade3 15s 0s infinite;
}
#-webkit-keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="slideshow3">
<figure>
<img src="http://lorempixel.com/300/300/nature/1" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/2" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/3" style="width:300px; height:300px;">
</figure>
</div>
Note: Even though, the hover selector takes precedence after doing one of the above changes, the animation still doesn't get paused in Edge alone. The changes mentioned above does fix the issue in Chrome, Firefox, Safari and it works in IE11, IE10 also.
The behavior in Edge seems to be very erratic. If you open this demo for the first time, the animation would be running and when you hover it will pause in Edge also but if you make any dummy changes to the code and click "Run" button, it no longer works. This is beyond explanation. I checked with few other fellow users in this chat room and everybody sees the same behavior in Edge.
Unfortunately there seems to be no way to get this to work in Edge. I have tried a variety of selector combinations (even tried inline styles with JS) but it is just not respecting the animation's play state change at all. The selector however is working perfectly fine. In the below snippet, you'd be able to notice the border changing on hover but nothing happens to the animation.
div.slideshow3 {
position: relative;
height: 300px;
width: 300px;
}
div.slideshow3 figure {
margin: 0;
position: absolute;
}
div.slideshow3:hover figure:nth-child(n) {
-webkit-animation-play-state: paused;
animation-play-state: paused;
border: 4px solid brown; /* hover border */
}
div.slideshow3 figure:nth-child(1) {
-webkit-animation: xfade3 15s 10s infinite;
animation: xfade3 15s 10s infinite;
border: 4px solid red; /* default border */
}
div.slideshow3 figure:nth-child(2) {
-webkit-animation: xfade3 15s 5s infinite;
animation: xfade3 15s 5s infinite;
border: 4px solid red; /* default border */
}
div.slideshow3 figure:nth-child(3) {
-webkit-animation: xfade3 15s 0s infinite;
animation: xfade3 15s 0s infinite;
border: 4px solid red; /* default border */
}
#-webkit-keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes xfade3 {
0% {
opacity: 1;
}
31.3% {
opacity: 1;
}
33.3% {
opacity: 0;
}
98% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="slideshow3">
<figure>
<img src="http://lorempixel.com/300/300/nature/1" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/2" style="width:300px; height:300px;">
</figure>
<figure>
<img src="http://lorempixel.com/300/300/nature/3" style="width:300px; height:300px;">
</figure>
</div>
In any browser you are going to have to work with different parameters as each browser is going to be different. That is something you will just have to accept. However, there are things that you can do to accommodate the different browsers. In order to force it to fit, from what I learned in my html class, you are going to have to adapt your h&w so that it fits within the every browser and then check every browser.
OR just understand that you cannot write a program, in html, to fit every browser.

Clipping an animated div

I'm trying to create a nice old CRT "tv" effect using animation in CSS, but having some problems with the scanlines displaying above and below the intended div.
What I have is a landing page that has 4 divs that link to other areas of the site. The 1st 2 divs are "TVs" each have a background showing the "tv" (static image) of the content of the link.
On a desktop or other larger screen, the 4 divs are displayed as 2x2, on a smaller screen it's shown in a 1x4 format.
I've created a single image that will be animated with css to fake the moving scanlines moving down the 1st 2 divs.
What's happening is that the "scanlines" appear above the "TVs" and move to below the "TVs".
You can see what's happening on JSFiddle:
http://jsfiddle.net/blyzz/ynekxcud/2/
Here's some cleansed HTML code:
<a href="URL1" target="_blank">
<div class="content" id="outside">
<div class="scanlines">
<div class="aniscan" id="aniscanout">
</div>
<div class="aniscan" id="aniscanout2">
</div>
</div>
</div>
</a>
<a href="URL2" target="_blank">
<div class="content" id="inside">
<div class="scanlines">
<div class="aniscan" id="aniscanin">
</div>
<div class="aniscan" id="aniscanin2">
</div>
</div>
</div>
</a>
and the accompanying cleansed CSS:
.content{
width: 300px;
min-width: 300px;
height: 125px;
min-height: 125px;
float:left;
margin: 5px;
border: 3px solid #555555;
z-index: -100;
}
.scanlines{
width: 100%;
height: 100%;
background-repeat: repeat;
z-index: 100;
}
.aniscan{
width: 100%;
height: 100%;
background-image: url('http://www.oocities.org/~special_effect/holo_scanlines.jpg');
background-repeat: repeat-x;
z-index: 200;
position: relative;
opacity:0.6;
}
#inside {
background-image: url('http://www.clipartbest.com/cliparts/xig/7rM/xig7rMriA.png');
border-radius: 0px 15px 0px 0px;
}
#outside{
background-image: url('http://cdn.graphicsfactory.com/clip-art/image_files/image/6/1347556-2587-Royalty-Free-Dog-With-Big-Bone-In-Mouth.jpg');
border-radius: 15px 0px 0px 0px;
}
#aniscanin{
-webkit-animation: mymove 5.2s linear infinite;
-moz-animation: mymove 5.2s linear infinite;
-o-animation: mymove 5.2s linear infinite;
animation: mymove 5.2s linear infinite;
}
#aniscanin2{
-webkit-animation: mymoveb 5.2s linear infinite;
-moz-animation: mymoveb 5.2s linear infinite;
-o-animation: mymoveb 5.2s linear infinite;
animation: mymoveb 5.2s linear infinite;
}
#aniscanout{
-webkit-animation: mymove 4.8s linear infinite;
-moz-animation: mymove 4.8s linear infinite;
-o-animation: mymove 4.8s linear infinite;
animation: mymove 4.8s linear infinite;
}
#aniscanout2{
-webkit-animation: mymoveb 4.8s linear infinite;
-moz-animation: mymoveb 4.8s linear infinite;
-o-animation: mymoveb 4.8s linear infinite;
animation: mymoveb 4.8s linear infinite;
}
#-webkit-keyframes mymove {
0% {top: -125px;}
100% {top: 0px;}
}
#keyframes mymove {
0% {top: -125px;}
100% {top: 0px;}
}
#-webkit-keyframes mymoveb{
0% {top: -125px;}
100% {top: 0px;}
}
#keyframes mymoveb {
0% {top: -125px;}
100% {top: 0px;}
}
I considered making a "window" with higher z-index divs above and below the 2 TVs, but it doesn't really work well with responsive design.
Any help would be appreciated!
P.S. It'd be nice if i could get the scanlines behind the rounded corners as well, but it's not really a deal-breaker - I can always remove the rounded corners.
You need overflow: hidden in your .content class:
Like this:
.content{
width: 300px;
min-width: 300px;
height: 125px;
min-height: 125px;
float:left;
margin: 5px;
border: 3px solid #555555;
z-index: -100;
overflow: hidden;
}
Fiddle:
http://jsfiddle.net/ynekxcud/3/