Reputation: 164
So I created a slideshow for a homepage, and it works fine on chrome but for some reason, on safari its only showing a gradient background but no images are shown.
#hero-image{
background-size:cover;
-webkit-background-size: cover;
background-repeat: no-repeat;
-moz-animation: slide 15s infinite;
-o-animation: slide 15s infinite;
animation: slide 15s infinite;
-webkit-animation: slide 15s infinite; /* Safari 4.0 - 8.0 */
#front-search-box{
color:white;
position:absolute;
background-color:transparent;
}
}
@-webkit-keyframes slide {
0% {
background: -webkit-linear-gradient(top,rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground2.png");
}
50%{
background: -webkit-linear-gradient(top,rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground3.png");
}
100%{
background: -webkit-linear-gradient(top,rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground4.png");
}
}
@-moz-keyframes slide{
0% {
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground2.png");
}
50%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground3.png");
}
100%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground4.png");
}
}
@-o-keyframes slide{
0% {
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground2.png");
}
50%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground3.png");
}
100%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground4.png");
}
}
@keyframes slide{
0% {
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground2.png");
}
50%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground3.png");
}
100%{
background: linear-gradient(rgba(0,0,0,1),rgba(0,0,0,0.3)), url("BlackBackground4.png");
}
}
Upvotes: 0
Views: 128
Reputation: 136648
Safari needs to have an default background-image
property set in order to be able to animate it in a keyframed animation. But beware, this browser really do animate between images states (shrinks + opacity transition).
Also, if the code pasted in your question was CSS, note that it is syntactically incorrect to nest declarations like you did with #front-search-box
.
Finally, note that if you do set the background
property inside an animation, it will reset all the more precise rules you could have set before (e.g background-cover
). Since here you are only changing the images, then use the background-image
property.
Updated example without all the outdated vendor prefixed things.
#hero-image {
width: 100vw;
height: 100vh;
background-size: cover;
-webkit-background-size: cover;
background-repeat: no-repeat;
animation: slide 15s infinite;
/* we need to set the default here for safari */
background-image: linear-gradient(rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.3)), url("aaa.png");
}
@keyframes slide {
0% {
background-image: linear-gradient(rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.3)), url("https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/John_William_Waterhouse_A_Mermaid.jpg/800px-John_William_Waterhouse_A_Mermaid.jpg");
}
50% {
background-image: linear-gradient(rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.3)), url("https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png");
}
100% {
background-image: linear-gradient(rgba(0, 0, 0, 1), rgba(0, 0, 0, 0.3)), url("https://upload.wikimedia.org/wikipedia/commons/d/dd/Heptagon_pavilion%2C_HK_%26_Kln_Fuk_Tak_Buddhist_Association.JPG");
}
}
<div id="hero-image"></div>
Upvotes: 1