Javascript 模态不';不要在Firefox上播放两次动画

Javascript 模态不';不要在Firefox上播放两次动画,javascript,jquery,html,css,modal-dialog,Javascript,Jquery,Html,Css,Modal Dialog,我有一个模式来查看只在Firefox上第一次播放动画的图片。当我第一次打开它时,它会工作,但当我第二次打开它时,它不会播放动画。它对Chrome tho有效 HTML <img src="https://s-media-cache-ak0.pinimg.com/236x/e8/2e/cc/e82ecc7ea98248bfa8161dcfcef2974a.jpg" id="postimage"></img> <div id="myModal" class="mod

我有一个模式来查看只在Firefox上第一次播放动画的图片。当我第一次打开它时,它会工作,但当我第二次打开它时,它不会播放动画。它对Chrome tho有效

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'">&times;</span>
  <img class="modal-content" id="modalImage">
</div>
JS

尝试添加:

.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;
}
并使用以下内容更新
.modal内容

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";
    }
}
-moz-
是专门针对Firefox的,
-webkit-
是针对Chrome或Opera的。找到这个了吗

影响动画的加速度,以便在不同的持续时间内调整速度

是动画循环播放然后停止的次数

影响动画如何将样式应用于目标

尝试添加:

.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;
}
并使用以下内容更新
.modal内容

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";
    }
}
-moz-
是专门针对Firefox的,
-webkit-
是针对Chrome或Opera的。找到这个了吗

影响动画的加速度,以便在不同的持续时间内调整速度

是动画循环播放然后停止的次数


影响动画如何将样式应用于目标

@kodecount用于什么目的?@kodecount很好,它不起作用。我已经试过了。问题是,如果它没有完全动画化,它会在firefox上再次动画化。如果动画结束,它将不会再次动画。@kodecount用于什么目的?@kodecount好吧,它不起作用。我已经试过了。问题是,如果它没有完全动画化,它会在firefox上再次动画化。如果动画结束,它就不会再动画了。这就成功了!你能解释一下吗?@Mirakurun更新了答案。这就成功了!你能解释一下吗?@Mirakurun更新了答案。