首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在没有<marquee>的HTML中选择。</marquee>

在没有<marquee>的HTML中选择。</marquee>
EN

Stack Overflow用户
提问于 2015-12-08 15:03:52
回答 2查看 9K关注 0票数 1

我试着编写一个滚动的文本,运行平稳。<marquee>..</marquee>标记在没有震动的情况下无法工作,我不认为它是好的编程。我想用JavaScript来做,但我完全是初学者。

我发现一些代码很容易理解,但我认为最好看的滚动文本对我来说是不连贯的。

也许有人能向我解释我不明白的部分。

代码:

代码语言: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中交换样式?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-12-08 15:28:42

嗯,marquee不仅不受欢迎,而且现在也是已过时了。

当然,您可以创建一个模拟效果的JavaScript函数。但使用CSS实现这一功能更简单,当然也更顺畅。

下面是一个例子:

代码语言:javascript
复制
<div class="wrapper">
    <p>Hey, how you're doing? Sorry you can't get through.</p>
</div>

CSS

代码语言:javascript
复制
.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

买前试一试

票数 5
EN

Stack Overflow用户

发布于 2015-12-08 15:27:39

我只想用CSS3 3动画。它在每一个现代浏览器中都能像魅力一样工作。您不需要JavaScript来移动元素。

如果您想要打开和关闭它,只需添加和删除一个CSS类。

我刚刚用codepen构建了一个示例:http://codepen.io/anon/pen/LGEBbx

这是动画代码:

代码语言:javascript
复制
@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

我希望这就是你要找的解决办法。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34159176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档