简体   繁体   English

CSS动画自动滚动文本问题

[英]CSS animation autroscrolling text issue

I have a autoscrolling text, the problem is that the animation restart before the div is complete. 我有一个自动滚动的文本,问题是动画在div完成之前重新启动。

You can have a look here: https://jsfiddle.net/2oLf47o9/2/ 您可以在这里看看: https : //jsfiddle.net/2oLf47o9/2/

Here it is the animation part 这是动画部分

-webkit-animation-name: move;
-webkit-animation-duration: 5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: up;
-webkit-animation-timing-function: linear;

I want to letters to scroll till the "Z" and restart again from the "A". 我想字母滚动到“ Z”,然后从“ A”重新开始。 How can I do that? 我怎样才能做到这一点?

in this case you'd better use transform:translate instead of a margin-top, since the former applies to the bounding box of a target (#box), while the latter to the container size. 在这种情况下,最好使用transform:translate而不是margin-top,因为前者适用于目标(#box)的边界框,而后者适用于容器大小。

 @-webkit-keyframes move {
    0% {
        transform:translateY(100%);
    }
    100% {
        transform:translateY(-100%);
    }
}

demo 演示

and version without "delays between iterations" 和版本不包含“迭代之间的延迟”

demo2 演示2

You just need to increase the margin height that the animation expects to reach when it is 100% complete. 您只需要增加动画100%完成时期望达到的边距高度即可。 In this case the CSS that sets that is: 在这种情况下,设置的CSS为:

@-webkit-keyframes move {
    0% {  /* Start of the animation */
        margin-top: 100vh;
    }
    100% { /* End of the animation */
        margin-top: -100vh;
    }
}

So you just have to change the margin the 100% version of the animation expects to something higher(and with the way vh units work this means setting the value lower), -200vh worked nicely when I tested the example. 因此,您只需要将动画的100%版本期望的边距更改为更高的值(并且通过vh单位的工作方式,这意味着将值设置得更低),-200vh在我测试示例时效果很好。

Changed code would be: 更改后的代码为:

100% { /* End of the animation */
    margin-top: -200vh;
}

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

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