I have a modal to view pictures which plays the animation only the first time on Firefox. When I open it first time, it works, but when I open it the second time, it doesn't play the animation. It works on Chrome tho.
我有一个模态来查看仅在Firefox上第一次播放动画的图片。当我第一次打开它时,它可以工作,但是当我第二次打开它时,它不会播放动画。它适用于Chrome tho。
HTML
HTML
<img src="https://s-media-cache-ak0.pinimg.com/236x/e8/2e/cc/e82ecc7ea98248bfa8161dcfcef2974a.jpg" id="postimage"></img>
<div id="myModal" class="modal">
<span class="close" onclick="document.getElementById('myModal').style.display='none'">×</span>
<img class="modal-content" id="modalImage">
</div>
CSS
CSS
.modal {
display: none;
position: fixed;
z-index: 999999;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0,0,0,0.8);
}
#postimage:hover {
opacity: 0.8;
cursor: pointer;
}
.modal-content {
display: block;
width: 100%;
margin: auto;
max-width: 720px;
}
@-webkit-keyframes fadeIn {
from {opacity:0.0}
to {opacity:1}
}
@keyframes fadeIn {
from {opacity:0.0}
to {opacity:1}
}
.modal-content {
-webkit-animation-name: fadeIn;
-webkit-animation-duration: 1.8s;
animation-name: fadeIn;
animation-duration: 1.8s;
}
.close {
position: absolute;
top: 50px;
right: 50px;
color: #e3e3e3;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
cursor: pointer;
color: #787878;
}
JS
JS
var modal = document.getElementById('myModal');
var img = document.getElementById('postimage');
var modalImg = document.getElementById("modalImage");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
}
var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
的jsfiddle
1 个解决方案
#1
2
Try adding:
尝试添加:
@-moz-keyframes fadeIn {
from {
opacity: 0.0;
}
to {
opacity: 1;
}
}
and updating the .modal-content
with:
并使用以下内容更新.modal-content:
-moz-animation-name: fadeIn;
-moz-animation-duration: 1.8s;
-moz-transition-timing-function: ease-in;
-moz-animation-iteration-count: 1;
-moz-animation-fill-mode: both;
-moz-
is specifically for Firefox as is -webkit-
is for Chrome or Opera. Found this on here
-moz-专门用于Firefox,因为-webkit-适用于Chrome或Opera。在这里找到了这个
transition-timing-function
effects acceleration of the animation so the speed can adjust with over various duration
transition-timing-function影响动画的加速度,因此速度可以在不同的持续时间内调整
animation-iteration-count
is the number of times an animation cycle will play then stop
animation-iteration-count是动画循环播放然后停止的次数
animation-fill-mode
effects how the animation applies styles to the target
动画填充模式会影响动画如何将样式应用于目标
#1
2
Try adding:
尝试添加:
@-moz-keyframes fadeIn {
from {
opacity: 0.0;
}
to {
opacity: 1;
}
}
and updating the .modal-content
with:
并使用以下内容更新.modal-content:
-moz-animation-name: fadeIn;
-moz-animation-duration: 1.8s;
-moz-transition-timing-function: ease-in;
-moz-animation-iteration-count: 1;
-moz-animation-fill-mode: both;
-moz-
is specifically for Firefox as is -webkit-
is for Chrome or Opera. Found this on here
-moz-专门用于Firefox,因为-webkit-适用于Chrome或Opera。在这里找到了这个
transition-timing-function
effects acceleration of the animation so the speed can adjust with over various duration
transition-timing-function影响动画的加速度,因此速度可以在不同的持续时间内调整
animation-iteration-count
is the number of times an animation cycle will play then stop
animation-iteration-count是动画循环播放然后停止的次数
animation-fill-mode
effects how the animation applies styles to the target
动画填充模式会影响动画如何将样式应用于目标