我已经使用JavaScript创建了新的div并设置了它的宽度和高度。紧接着,我需要将它调整到100%的宽度,并带有过渡效果。但只有当编辑样式在Timeout函数内时才会显示。没有它,只是跳到新的宽度。Css转换仅在超时函数内部显示
的CSS:
#project-detail {
@extend .project-detail-preview;
transition: width 0.25s ease-out, top 0.25s ease-out, left 0.25s ease-out, height 0.25s ease-out;
}
脚本:
var detailContainer = document.createElement("div");
detailContainer.id = "project-detail";
detailContainer.innerHTML = previewContent.innerHTML;
detailContainer.style.width = previewWidth;
detailContainer.style.height = previewHeight;
blocksContainer.appendChild(detailContainer);
for (let project of source.projects) {
if(project.id == projectID) {
setTimeout(function() {
detailContainer.style.width = "100%";
}, 1);
}
}
期待沉默downvotes在3 ... 2 ... 1 ... –
好的,感谢您的解释!我花了大约四个小时才意外地发现这个解决方案..现在至少我知道它是如何工作:) – sapharick
很高兴我帮助!这是否值得赞扬和接受答案? :) –