javascript - 带有节点 appendChild() html 的动画

标签 javascript html dom web

我是网络开发的新手,我正在尝试创建一个网页,该网页将在单击按钮时向下延伸页面。我找到了 this link ,其中包含以下代码:

HTML:

<ul id="myList"><li>Coffee</li><li>Tea</li></ul>

<p id="demo">Click the button to append an item to the list</p>

<button onclick="myFunction()">Try it</button>

JavaScript:

function myFunction()
{
    var node=document.createElement("LI");
    var textnode=document.createTextNode("Water");
    node.appendChild(textnode);
    document.getElementById("myList").appendChild(node);
}

这将添加信息。我想这样做,所以它会动画化,而不仅仅是出现。我该怎么做?

感谢任何帮助或教程。谢谢!

最佳答案

您可以使用 Element.animate()。 有关更多信息,请阅读 this .

例子:

    const div = document.createElement('div');
    div.innerText = 'text'; 
    otherElenet.appendChild(div);
    div.animate([
        // keyframes
        { opacity: '0' },
        { opacity: '1' }
    ], {
        // timing options
        duration: 1000,
    });

Notice, It is not supported by IE

关于javascript - 带有节点 appendChild() html 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14300210/

相关文章:

javascript - 尝试将数据推送到 WebView 中的 JS 函数

javascript - 如何用JS选择动态创建的特定元素?

c++ - 快速选择 DOM 中的元素

javascript - 第一个使用 ajax 的小型食品店项目 - 不执行

javascript - Laravel 4 如何防止 js 注入(inject)?

javascript - Plotly.js 图没有响应

html - 如何有一个粗体标题文本?

javascript - 为什么 Angular2 选择器中不能使用句点?

javascript - 为什么我不能要求构造函数并立即将其与 browserify 一起使用?

javascript - flexbox 图像选择