想要在文本消失时从右边显示文本

huangapple go评论64阅读模式
英文:

Want to show the text from right when it disappears

问题

在动画结束时,文本完全消失,我想要从右侧显示正在消失的文本,我不想让文本完全消失。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
.wrapper {
  position: relative;
  overflow: hidden;
  height: 25px;
  width: 100%;
  border: 1px solid orange;
}

.wrapper p {
  position: absolute;
  margin: 0;
  line-height: 25px;
  white-space: nowrap;
  animation: marquee 5s linear infinite;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

<!-- language: lang-html -->
<div class="wrapper">
    <p>嗨,你好吗?抱歉,你无法通过。</p>
</div>

<!-- end snippet -->
英文:

At the end of the animation the text is completely disappearing I want to show it from right the text which is disappearing I don't want to disappear the text completely

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.wrapper {
  position: relative;
  overflow: hidden;
  height: 25px;
  width: 100%;
  border: 1px solid orange;
}

.wrapper p {
  position: absolute;
  margin: 0;
  line-height: 25px;
  white-space: nowrap;
  animation: marquee 5s linear infinite;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

<!-- language: lang-html -->

&lt;div class=&quot;wrapper&quot;&gt;
    &lt;p&gt;Hey, how you&#39;re doing? Sorry you can&#39;t get through.&lt;/p&gt;
&lt;/div&gt;

<!-- end snippet -->

答案1

得分: 2

.wrapper {
    position: relative;
    overflow: hidden;
    height: 25px;
}

.wrapper div {
    display: flex;
    width: 200%;
    position: absolute;
    overflow: hidden;
    animation: marquee 8s linear infinite;
}

.wrapper span {
    width: 50%;
}

@keyframes marquee {
    0% {
        left: 0;
    }

    100% {
        left: -100%;
    }
}
<div class="wrapper">
    <div>
        <span>嗨,你好吗?很抱歉你打不通电话。</span>
        <span>嗨,你好吗?很抱歉你打不通电话。</span>
    </div>
</div>
英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.wrapper {
    position: relative;
    overflow: hidden;
    height: 25px;
}

.wrapper div {
    display: flex;
    width: 200%;
    position: absolute;
    overflow: hidden;
    animation: marquee 8s linear infinite;
}

.wrapper span {
    width: 50%;
}

@keyframes marquee {
    0% {
        left: 0;
    }

    100% {
        left: -100%;
    }
}

<!-- language: lang-html -->

    &lt;div class=&quot;wrapper&quot;&gt;
        &lt;div&gt;
            &lt;span&gt;Hey, how you&#39;re doing? Sorry you can&#39;t get through.&lt;/span&gt;
            &lt;span&gt;Hey, how you&#39;re doing? Sorry you can&#39;t get through.&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;

<!-- end snippet -->

Hope that work for you and got your answer 想要在文本消失时从右边显示文本

答案2

得分: 0

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

这个动画的作用是将 div 从其原始位置移动 +100% 的宽度,到其原始位置 -100% 的宽度(即原始位置的左侧)。

使用 transform: translateX(0%) 可以将其移动到原始位置。

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(0%); }
}

您需要更改 .wrapper p 中的 animation 参数,以使动画不重复播放,由于现在覆盖的距离较短,速度会比预期慢。

animation: marquee 5s linear infinite; 更改为 animation: marquee 2s linear;

<!-- begin snippet: js hide: false console: true babel: null -->

<!-- language: lang-css -->

.wrapper {
  position: relative;
  overflow: hidden;
  height: 25px;
  width: 100%;
  border: 1px solid orange;
}

.wrapper p {
  position: absolute;
  margin: 0;
  line-height: 25px;
  white-space: nowrap;
  animation: marquee 2s linear;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(0%); }
}

<!-- language: lang-html -->

&lt;div class=&quot;wrapper&quot;&gt;
    &lt;p&gt;Hey, how you&#39;re doing? Sorry you can&#39;t get through.&lt;/p&gt;
&lt;/div&gt;

<!-- end snippet -->


<details>
<summary>英文:</summary>

```css
@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

This animation means to move the div from its original position + 100% of its width, to its original position -100% of its width (which is to the left of its original position).

Using transform: translateX(0%) should move it to its original position.

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(0%); }
}

You would have to change animation parameters in .wrapper p so that the animation doesn't keep repeating, and since the distance covered is now shorter, the speed would be slower than intended.

From animation: marquee 5s linear infinite; to animation: marquee 2s linear;

<!-- begin snippet: js hide: false console: true babel: null -->

<!-- language: lang-css -->

.wrapper {
  position: relative;
  overflow: hidden;
  height: 25px;
  width: 100%;
  border: 1px solid orange;
}

.wrapper p {
  position: absolute;
  margin: 0;
  line-height: 25px;
  white-space: nowrap;
  animation: marquee 2s linear;
}

@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(0%); }
}

<!-- language: lang-html -->

&lt;div class=&quot;wrapper&quot;&gt;
    &lt;p&gt;Hey, how you&#39;re doing? Sorry you can&#39;t get through.&lt;/p&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月11日 12:11:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76658665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定