简体   繁体   English

定时滑动文本框

[英]Timed sliding text-box

I'm looking for a way to animate my text box so that it slides into frame from the right side at (x) amount of time.我正在寻找一种方法来为我的文本框设置动画,以便它在 (x) 时间内从右侧滑入框架。 So far, I haven't found any online resources that could help me with this animation.到目前为止,我还没有找到任何可以帮助我解决这个 animation 的在线资源。

For now, I just have a simple (absolute) box.现在,我只有一个简单的(绝对的)盒子。

 .taskbox { width: 230px; padding: 15px; position: absolute; right: 25px; top: 25px; background-color: black; color: white; font-family: courier new; font-size: 20px; }
 <div class="taskbox">Evidently, the pandemic has taken a toll on the economy. You should find a way to financially stay afloat. Humans have something called 'stipends' to aide in a situation like this. We should <a href="a2_page_3.html">investigate</a>!</div>

Note: Not too sure if this will require JavaScript, but I have preexisting functions for elements not involved in my question.注意:不太确定这是否需要 JavaScript,但我有针对我的问题未涉及的元素的预先存在的功能。 If my script is needed, I'm more than happy to update my post.如果需要我的脚本,我非常乐意更新我的帖子。

Thanks in advance for your help!在此先感谢您的帮助!

This can be done with CSS only with animation you can specify a duration as well as a delay (in your case x).这可以使用 CSS 完成,仅使用animation您可以指定持续时间和延迟(在您的情况下为 x)。 Paradoxically to make an element slide from the right it easier to positioned it with the left property.矛盾的是,使元素从右侧滑动更容易使用left属性定位它。 Like so…像这样……

 .taskbox { width: 230px; padding: 15px; left: 100%; position: absolute; top: 25px; background-color: black; color: white; font-family: courier new; font-size: 20px; animation: slide-from-right.4s 2s forwards; /* x = 2s */ } @keyframes slide-from-right { to { left: calc(100% - 230px - 30px - 25px); /* 100% = total width, 230px = element width, 30px = left and right padding, 25px = distance from right border */ } }
 <div class="taskbox">Evidently, the pandemic has taken a toll on the economy. You should find a way to financially stay afloat. Humans have something called 'stipends' to aide in a situation like this. We should <a href="a2_page_3.html">investigate</a>!</div>

You could animate transform: translate :您可以为transform: translate设置动画:

 .taskbox { width: 230px; padding: 15px; position: absolute; right: 25px; top: 25px; background-color: black; color: white; font-family: courier new; font-size: 20px; transform: translate3d(calc(100% + 25px), 0, 0); animation: slide-in 0.5s 1s cubic-bezier(0.3, 1.3, 0.9, 1) forwards; } @keyframes slide-in { to { transform: translate3d(0, 0, 0); } }
 <div class="taskbox">Evidently, the pandemic has taken a toll on the economy. You should find a way to financially stay afloat. Humans have something called 'stipends' to aide in a situation like this. We should <a href="a2_page_3.html">investigate</a>!</div>

In case you're wondering why I'm using translate3d , it triggers hardware acceleration.如果您想知道我为什么使用translate3d ,它会触发硬件加速。 Check out this article if you're interested . 如果您有兴趣,请查看这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM