选取框,以内容方式更改内容并重新开始滚动(Marquee, change content dynamically and restart scrolling)

编程入门 行业动态 更新时间:2024-10-27 06:32:34
选取框,以内容方式更改内容并重新开始滚动(Marquee, change content dynamically and restart scrolling)

我的网站上有一个marquee :

<marquee>Hello! <span id="text">Welcome to my website.</span></marquee>

我想从marquee中用id="text"改变span的内容:

setTimeout(function() {
  document.getElementById("text").innerHTML = "This is my website. Happy reading!";
}, 5000); 
  
<marquee>Hello! <span id="text">Welcome to my website.</span>
</marquee> 
  
 

一切运作良好。 问题是我想在更改文本后从头开始重新启动选取框。 想象一下,第一个文本是一个较长的文本,当与另一个文本进行更改时,它在第一次滚动时不会完全可读; 访客将从中间看到它。

所以,我想从头开始重新启动选框滚动。

谢谢!

I have a marquee on my website:

<marquee>Hello! <span id="text">Welcome to my website.</span></marquee>

I want to change dynamically the content of the span with id="text" from marquee:

setTimeout(function() {
  document.getElementById("text").innerHTML = "This is my website. Happy reading!";
}, 5000); 
  
<marquee>Hello! <span id="text">Welcome to my website.</span>
</marquee> 
  
 

All works well. The problem is that I want to restart the marquee, from the beginning after changing the text. Imagine first text is a longer one, when changing with another, it will not be entirely readable at first scroll; the visitor will see it from middle.

So, I want to restart the marquee scroll from beginning.

最满意答案

也许不是你想要或期望的。 但这应该重新开始。 我将使用新元素删除并重新插入DOM中的选取框。

setTimeout(function() {
  document.getElementById("marquee").innerHTML = '<marquee>Hello! <span id="text">This is my website. Happy reading!</span></marquee>';
}, 5000); 
  
<div id="marquee">
<marquee>Hello! <span id="text">Welcome to my website.</span>
</marquee>
</div> 
  
 

Maybe not what you want or expect. But this should restart the marquee. I would delete and reinsert the marquee in the DOM with a new element.

setTimeout(function() {
  document.getElementById("marquee").innerHTML = '<marquee>Hello! <span id="text">This is my website. Happy reading!</span></marquee>';
}, 5000); 
  
<div id="marquee">
<marquee>Hello! <span id="text">Welcome to my website.</span>
</marquee>
</div> 
  
 

更多推荐

本文发布于:2023-08-07 03:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1460695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   方式   Marquee   change   scrolling

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!