请教:js 实现平滑滚动字幕
想实现公告文字循环从右滚到左,用HTML自带的标签<marguee>,滚动很闪,看不清,而且鼠标移过去不能停止
------解决方案--------------------
3点说明:
1.marquee标签可以设置使得鼠标移过去,停止
如:
HTML code<marquee onmouseout="this.start()" onmouseover="this.stop()">用来设置鼠标移出该区域时继续滚动</marquee>
------解决方案--------------------
HTML code<style>#s{ width:500px; border:1px solid #000; overflow:hidden;}#s div{ width:1000px;}#s #i span{ width:500px; display:block; float:left;}</style><div id="s"><div id="i"><span id="t">要滚动的文字,滚啊滚,滚啊滚</span></div></div><script type="text/javascript">var speed = 10var s = document.getElementById("s")var i = document.getElementById("i")var t = document.getElementById("t")i.appendChild(t.cloneNode(true))function scroll(){ s.scrollLeft += 1 if(s.scrollLeft >= t.offsetWidth) s.scrollLeft = 0;}window.setInterval(scroll,speed)</script>
------解决方案--------------------
HTML code<style>#s{ width:500px; border:1px solid #000; overflow:hidden;}#s div{ width:1000px;}#s #i span{ width:500px; display:block; float:left;}</style><div id="s"><div id="i"><span id="t">要滚动的文字,滚啊滚,滚啊滚</span></div></div><script type="text/javascript">var speed = 10var s = document.getElementById("s")var i = document.getElementById("i")var t = document.getElementById("t")var d i.appendChild(t.cloneNode(true))function scroll(){ s.scrollLeft += 1 if(s.scrollLeft >= t.offsetWidth) s.scrollLeft = 0;}d = window.setInterval(scroll,speed)s.onmouseover = function(){window.clearInterval(d)}s.onmouseout = function(){d = window.setInterval(scroll,speed)}</script>
------解决方案--------------------
查询谷 - www.chaxungu.com
请问:js 实现平滑滚动字幕
编辑:chaxungu时间:2022-10-02 23:15:51分类:web开发