如何在React中一个字母一个字母地删除段落



我想一个字母一个字母地动画删除HTML段落的一部分,就像按下delete键一样。可以重要地说,文本跨越多行。

<p className="paragraph1">
<span className="keep">Text that should not be deleted.</span>
<span className="hide">Text that should be deleted.</span>
<span className="keep">More text that should not be deleted.</span>
</p>
<p className="paragraph2">
<span className="keep">Text that should not be deleted.</span>
<span className="keep">More text that should not be deleted.</span>
<span className="hide">Text that should be deleted.</span>
</p>

如果使用React,则不应该访问DOM来显示或修改文本。

const words = ["CSS3.", "HTML5.", "javascript."];

字符串应该来自更实用的方法的props,或者存储在组件的状态中。然后,您可以简单地使用超时来修改状态。

当然,在段落中显示状态。

最新更新