首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定时滑动文本框

定时滑动文本框
EN

Stack Overflow用户
提问于 2020-12-04 06:47:54
回答 2查看 36关注 0票数 0

我正在寻找一种方法来动画我的文本框,以便它滑动到帧从右侧在(x)的时间量。到目前为止,我还没有找到任何可以帮助我制作这个动画的在线资源。

现在,我只有一个简单的(绝对)框。

代码语言:javascript
复制
.taskbox {
  width: 230px;
  padding: 15px;
  position: absolute;
  right: 25px;
  top: 25px;
  background-color: black;
  color: white;
  font-family: courier new;
  font-size: 20px;
}
代码语言:javascript
复制
<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>

注意:不太确定这是否需要JavaScript,但我已经为我的问题中没有涉及的元素提供了预先存在的函数。如果需要我的脚本,我非常乐意更新我的帖子。

提前感谢您的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-04 07:34:54

这可以用CSS来完成,只用animation你可以指定一个持续时间和一个延迟(在你的例子中是x)。矛盾的是,要使元素从右侧滑动,使用left属性定位它会更容易。就像这样的…

代码语言:javascript
复制
.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 */
  }
}
代码语言:javascript
复制
<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>

票数 3
EN

Stack Overflow用户

发布于 2020-12-04 08:10:00

您可以为transform: translate设置动画

代码语言:javascript
复制
.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);
  }
}
代码语言:javascript
复制
<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>

如果你想知道我为什么要使用translate3d,它会触发硬件加速。Check out this article if you're interested

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65135353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档