2 回答

TA貢獻1797條經驗 獲得超6個贊
您可以制作一個 CSS動畫,并在單擊按鈕時播放該動畫。
let htmlcontent = `<p>It's me again!</p>`;
let content = document.getElementById("content");
function animation() {
? content.innerHTML = htmlcontent;
??
? content.classList.add("animate");
??
? setTimeout(function() {
? ? content.classList.remove("animate");
? }, 500); // 500 is the same time as the CSS animation
}
#content p {
? font-size: 100px;
}
.animate {
? animation: fadeIn 500ms ease-out backwards;
}
@keyframes fadeIn {
? from {
? ? transform: translateX(250px);
? ? opacity: 0;
? }
? to {
? ? transform: translateX(0px);
? ? opacity: 1;
? }
}
<div id="content">
? <p>
? Hello world!
? </p>
</div>
<button onclick="animation()">
? Click here
</button>
添加回答
舉報