gpt4 book ai didi

Javascript 阻止 css?

转载 作者:行者123 更新时间:2023-11-28 06:17:41 28 4
gpt4 key购买 nike

我正在构建一个灯箱相册。当第一个图像加载时,CSS 转换起作用。当加载后的每个图像都没有。任何想法为什么?加载第一张之后的照片,但没有过渡。

Image.prototype.load = function(url){
var thisImg = this;
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open('GET', url,true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.onload = function(e) {
var blob = new Blob([this.response]);
thisImg.src = window.URL.createObjectURL(blob);
};
xmlHTTP.onprogress = function(e) {
thisImg.completedPercentage = parseInt((e.loaded / e.total) * 100);
};
xmlHTTP.onloadstart = function() {
thisImg.completedPercentage = 0;
};
xmlHTTP.onloadend = function() {
thisImg.completedPercentage = 0;
gallery.appendChild(currentImage);
gallery.className = "gallery toggle";
};
xmlHTTP.send();
};
.gallery {
display: absolute;
position: fixed;
margin: auto;
visibility: hidden;
opacity: 0;
-moz-transition: opacity 0.5s, visibility 0.5s ease-in-out;
-webkit-transition: opacity 0.5s, visibility 0.5s ease-in-out;
-ms-transition: opacity 0.5s, visibility 0.5s ease-in-out;
transition: opacity 0.5s, visibility 0.5s ease-in-out;
background: rgba(0, 0, 0, 0.0);
width: 96%;
height: 96%;
margin-top: 2%;
margin-left: 2%;
overflow: hidden;
z-index: 1001;
}

.gallery.toggle {
visibility: visible;
opacity: 1;
}

最佳答案

您的 CSS 在页面加载时执行。当您动态添加或删除内容时,CSS 不会再次加载。加载图像后,您可能必须使用 JS 创建转换。

也许这有帮助:

https://timtaubert.de/blog/2012/09/css-transitions-for-dynamically-created-dom-elements/

关于Javascript 阻止 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35800269/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com