我在的jsfiddle的腳本作品:https://jsfiddle.net/oxw4e5yh/腳本作品中的jsfiddle而不是HTML文檔
然而,在HTML文檔它不工作:
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
function calcSpeed(speed) {
// Time = Distance/Speed
var spanSelector = document.querySelectorAll('.marquee span'),
i;
for (i = 0; i < spanSelector.length; i++) {
var spanLength = spanSelector[i].offsetWidth,
timeTaken = spanLength/speed;
spanSelector[i].style.animationDuration = timeTaken + "s";
}
}
calcSpeed(75);
</script>
<style>
/* Make it a marquee */
.marquee {
width: 100%;
left: 0px;
height: 10%;
position: fixed;
margin: 0 auto;
white-space: nowrap;
overflow: hidden;
background-color: #000000;
bottom: 0px;
color: white;
font: 50px'Verdana';
}
.marquee span {
display: inline-block;
padding-left: 100%;
text-indent: 0;
animation: marquee linear infinite;
animation-delay: 5s;
background-color: #000000;
color: white;
bottom: 0px;
}
/* Make it move */
@keyframes marquee {
0% {
transform: translate(10%, 0);
}
100% {
transform: translate(-100%, 0);
}
}
/* Make it pretty */
.scroll {
padding-left: 1.5em;
position: fixed;
font: 50px'Verdana';
bottom: 0px;
color: white;
left: 0px;
height: 10%;
}
</style>
</head>
<body>
<div class="marquee">
<span>Lots of text, written in a long sentance to make it go off the screen. Well I hope it goes off the screen</span>
</div>
</body>
</html>
的腳本是一個CSS和JavaScript選取框控制滾動文本的穩定速度。
任何想法我失蹤?
另外,正如您在小提琴上所看到的,文本開始滾動需要一段時間。我可以減少延遲嗎?
當您嘗試在jsfiddle之外使用它時,您可以更具體地瞭解哪些功能無法正常工作嗎?當您嘗試運行控制檯時,控制檯是否會提供任何消息? – JoeL
在文檔準備就緒前,您的JavaScript正在運行 – phuzi
當我使用它時,您的小提琴已損壞。除非一個大的黑色固體盒子是你期望的 – 8protons