自动垂直滚动div内容循环

发布于 2024-08-15 23:57:44 字数 183 浏览 10 评论 0原文

我正在尝试找到一种简单的方法,让只有文本的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

思念绕指尖 2024-08-22 23:57:45

这可能不是传统的,但你可以尝试 标签,

它在 IE 和 FF 中都有效,而且我上次检查时,safari 也是如此。

<marquee behavior="scroll" direction="up" height="250" 
   scrollamount="2" scrolldelay="10"">
  Your content goes here
</marquee>

应该给你你想要的,
您可以像任何

...
那样设置它们的样式
然后还有一个额外的优点,就是没有 javascript...

编辑以响应您的评论

它会变得更好,在任何浏览器中尝试这个

onmouseover="this.stop()" onmouseout="this.start()"

在 IE 中

style="filter:progid:DXImageTransform.Microsoft.Alpha( Opacity=0,
FinishOpacity=100, 
Style=1, StartX=0,  FinishX=0, StartY=0, FinishY=10) 
progid:DXImageTransform.Microsoft.Alpha( Opacity=100, FinishOpacity=0, 
Style=1, StartX=0, FinishX=0, StartY=90, FinishY=100)" 

作为选取框标记的属性...

This might not be conventional but you can try the <marquee> tag

it works both in IE and FF, and the last time I checked, safari too.

<marquee behavior="scroll" direction="up" height="250" 
   scrollamount="2" scrolldelay="10"">
  Your content goes here
</marquee>

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

onmouseover="this.stop()" onmouseout="this.start()"

And this in IE

style="filter:progid:DXImageTransform.Microsoft.Alpha( Opacity=0,
FinishOpacity=100, 
Style=1, StartX=0,  FinishX=0, StartY=0, FinishY=10) 
progid:DXImageTransform.Microsoft.Alpha( Opacity=100, FinishOpacity=0, 
Style=1, StartX=0, FinishX=0, StartY=90, FinishY=100)" 

As attributes of the marquee tag...

转角预定愛 2024-08-22 23:57:45
function scrollDivUp(id){
    document.getElementById(id).scrollTop-=1
    timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

也许尝试类似的事情。

您还可以将 .scrollTop-=1 更改为 .scrollTop+=1 以另一种方式滚动。

您还需要一个可滚动的 div,可以通过限制大小并设置溢出样式属性来完成,即。样式=“宽度:200px;高度:300px;溢出:自动”

function scrollDivUp(id){
    document.getElementById(id).scrollTop-=1
    timerUp=setTimeout("scrollDivUp('"+id+"')",10)
}

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"

北渚 2024-08-22 23:57:45

尝试更改 div 的 scrollTop这里有一个示例

Try changing the div's scrollTop. There is an example here.

年华零落成诗 2024-08-22 23:57:45

我看到还没有给出正确答案。我认为你必须看看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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文