我试着编写一个滚动的文本,运行平稳。<marquee>..</marquee>标记在没有震动的情况下无法工作,我不认为它是好的编程。我想用JavaScript来做,但我完全是初学者。
我发现一些代码很容易理解,但我认为最好看的滚动文本对我来说是不连贯的。
也许有人能向我解释我不明白的部分。
代码:
var marqueewidth="2400px"
var marqueeheight="45px"
var speed=1
var pause=1 //stop by mouseover 0=no. 1=yes
var marqueecontent='<nobr><span style="font-size:40px">*** Wir wünschen einen guten Start in den Dezember!!! ***</span></nobr>'
var newspeed=speed
var pausespeed=(pause==0)? newspeed: 0
document.write('<span id="temp" style="visibility:hidden; position:absolute; top:0px; left:-9000px">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee
function populate(){
cross_marquee= document.getElementById("marquee")
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
cross_marquee.innerHTML=marqueecontent
actualwidth=document.getElementById("temp").offsetWidth
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate
function scrollmarquee(){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-newspeed+"px"
else
cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
}
with (document){
write('<div style="position:relative; top:655px; width:'+marqueewidth+'; height:'+marqueeheight+'; overflow:hidden">')
write('<div onMouseover="newspeed=pausespeed" onMouseout="newspeed=speed">')
write('<div id="marquee" style="position:absolute; left:0px; top:0px; "></div>')
write('</div></div>')
}问:为什么我需要临时的div?我如何在CSS中交换样式?
发布于 2015-12-08 15:28:42
嗯,marquee不仅不受欢迎,而且现在也是已过时了。
当然,您可以创建一个模拟效果的JavaScript函数。但使用CSS实现这一功能更简单,当然也更顺畅。
下面是一个例子:
<div class="wrapper">
<p>Hey, how you're doing? Sorry you can't get through.</p>
</div>CSS
.wrapper {
position: relative;
overflow: hidden;
height: 25px;
width: 100px;
border: 1px solid orange;
}
.wrapper p {
position: absolute;
margin: 0;
line-height: 25px;
white-space: nowrap;
animation: marquee 5s linear infinite;
}
@keyframes marquee {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}Demo
买前试一试
发布于 2015-12-08 15:27:39
我只想用CSS3 3动画。它在每一个现代浏览器中都能像魅力一样工作。您不需要JavaScript来移动元素。
如果您想要打开和关闭它,只需添加和删除一个CSS类。
我刚刚用codepen构建了一个示例:http://codepen.io/anon/pen/LGEBbx
这是动画代码:
@keyframes marquee {
0% { transform: translateX(100%); }
100% { transform: translateX(-100%); }
}我希望这就是你要找的解决办法。
https://stackoverflow.com/questions/34159176
复制相似问题