【发布时间】:2012-05-27 14:33:00
【问题描述】:
我想创建一个在网站上来回滚动的动画 HTML“字幕”:
<div class="marquee">This is a marquee!</div>
和 CSS:
.marquee {
position: absolute;
white-space: nowrap;
-webkit-animation: rightThenLeft 4s linear;
}
@-webkit-keyframes rightThenLeft {
0% {left: 0%;}
50% {left: 100%;}
100% {left: 0%;}
}
问题是,选取框在到达屏幕的右侧边缘时并没有停止;它一直移出屏幕(短暂地出现一个水平滚动条),然后又回来了。
那么,如何让选取框在右边缘到达屏幕右边缘时停止?
编辑:奇怪的是,这不起作用:
50% {right: 0%}
【问题讨论】:
-
使用javascript通过css属性停止动画
-
@Webtecher javascript 如何知道何时停止动画?
-
而不是 left: 100% 应该是 left:
100% - ( number of characters in string * space taken by single character )现在,显然你不会在 css 中做这样的事情。所以最好不要使用left或right,而是使用margin-left或margin-right。 -
是的,但还是不行,即使你把我的代码改成
margin-left
标签: css animation marquee keyframe