自动垂直滚动div内容循环
我正在尝试找到一种简单的方法,让只有文本的 div 自动垂直滚动文本。我不想使用框架(尽管我确实使用 Prototype,所以如果使用 Prototype 更容易,那就没问题,但没有 Scriptalicious)。
我认为必须有一种方法可以用几行代码来做到这一点,但我对 Javascript 不够熟悉,不知道如何最有效地做到这一点。
I am trying to find a simple way to have a div with just text in it automatically scroll the text vertically. I don't want to use a framework (though I do use Prototype, so if it is easier using Prototype then that is fine, but no Scriptalicious).
I assume there has got to be a way to do this with a few lines of code, but I am not familiar enough with Javascript to know how to most effectively do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可能不是传统的,但你可以尝试
它在 IE 和 FF 中都有效,而且我上次检查时,safari 也是如此。
应该给你你想要的,
您可以像任何
...
那样设置它们的样式
然后还有一个额外的优点,就是没有 javascript...
编辑以响应您的评论
它会变得更好,在任何浏览器中尝试这个
在 IE 中
作为选取框标记的属性...
This might not be conventional but you can try the
<marquee>
tagit works both in IE and FF, and the last time I checked, safari too.
should give you what you want,
and you can style them like any
<div>
...and then there is the added advantage of having no javascript...
Edit in response to your comment
It gets better, try this in any browser
And this in IE
As attributes of the marquee tag...
也许尝试类似的事情。
您还可以将 .scrollTop-=1 更改为 .scrollTop+=1 以另一种方式滚动。
您还需要一个可滚动的 div,可以通过限制大小并设置溢出样式属性来完成,即。样式=“宽度:200px;高度:300px;溢出:自动”
try something like that maybe.
you could also change the .scrollTop-=1 to .scrollTop+=1 to scroll the other way.
You would also need a scrollable div which can be done by constraining the size and setting the overflow style property ie. style="width:200px; height:300px; overflow:auto"
尝试更改 div 的 scrollTop。 这里有一个示例。
Try changing the div's scrollTop. There is an example here.
我看到还没有给出正确答案。我认为你必须看看cloneNode() 例如。并克隆您想要滚动的元素。当第一个元素位于滚动的最后一点时,将重复的元素放置在第一个元素之后。当重复的元素快到末尾时,将原始元素放在重复元素之后,依此类推!
I see that the correct answer isn't given yet. I think you have to look at cloneNode() for instance. And clone the element you want to scroll. When the first element is at the last point of scrolling then place the duplicated element after the first element. And when that duplicated element is almost at the end, place the original after the duplicate and so on!