3

我正在学习 Java Script,我在网上找到了一个用于滚动文本的免费脚本。我的目标是在一个页面上多次使用它,但我不能多次使用它并让它工作,我希望你能提供帮助。这是 HTML:

<head>
    <meta charset="utf-8" />
    <title>Scrollers</title>
</head>
<body style="background-color:#3c3c3c">
    <br />
    <script type="text/javascript" src="d:(...)\my documents\visual studio 2013\Projects\scrolling text\scroller 1.js"></script>
    <br />
    <script type="text/javascript" src="d:(...)\my documents\visual studio 2013\Projects\scrolling text\scroller 2.js"></script>
</body>

我的 Java 脚本脚本:

var memorywidth = "1850px" //scroller width
var memoryheight = "140px" //scroller height
var memorybgcolor = "#000000" //scroller background
var memorypadding = "5px" //padding applied to the scroller. 0 for non.
var borderCSS = "border: 1px solid black;" //Border CSS, applied to scroller to give border.

var memoryspeed = 5 //Scroller speed (larger is faster 1-10)
var pauseit = 1 //Pause scroller onMousever (0=no. 1=yes)?

var persistlastviewedmsg = 1 //should scroller's position persist after users navigate away (1=yes, 0=no)?
var persistmsgbehavior = "onload" //set to "onload" or "onclick".

//Specify the scroller's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

var memorycontent = '<span style="color: #FFFFFF; font-family: Consolas; font-size:120px"><strong style="color:#B54646">04-11-2013</strong> - \
            FTs de alta dentro do SLA: 89% <img src="http://imageshack.com/a/img18/9017/uz2b.png" height="100" width="70">;\
            FTs de alta fora do SLA: 12% <img src="http://imageshack.com/a/img18/9017/uz2b.png" height="100" width="70">;\
            FTs de alta em TNE: 92% <img src="http://imageshack.com/a/img585/9553/1sgm.png" height="100" width="70">;\
            FTs de alta em TNO: 99% <img src="http://imageshack.com/a/img18/9017/uz2b.png" height="100" width="70">;\
            FTs de alta em TCO: 73% <img src="http://imageshack.com/a/img585/9553/1sgm.png" height="100" width="70">;\
            </span>'


////NO NEED TO EDIT BELOW THIS LINE////////////
var combinedcssTable = "width:" + (parseInt(memorywidth) + 6) + "px;background-color:" + memorybgcolor + ";padding:" + memorypadding + ";" + borderCSS + ";"
var combinedcss = "width:" + memorywidth + ";height:" + memoryheight + ";"

var divonclick = (persistlastviewedmsg && persistmsgbehavior == "onclick") ? 'onClick="savelastmsg()" ' : ''
memoryspeed = (document.all) ? memoryspeed : Math.max(1, memoryspeed - 1) //slow speed down by 1 for NS
var copyspeed = memoryspeed
var pausespeed = (pauseit == 0) ? copyspeed : 0
var iedom = document.all || document.getElementById
if (iedom)
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-10000px">' + memorycontent + '</span>')
var actualwidth = ''
var memoryscroller

if (window.addEventListener)
    window.addEventListener("load", populatescroller, false)
else if (window.attachEvent)
    window.attachEvent("onload", populatescroller)
else if (document.all || document.getElementById)
    window.onload = populatescroller

function populatescroller() {
    memoryscroller = document.getElementById ? document.getElementById("memoryscroller") : document.all.memoryscroller
    memoryscroller.style.left = parseInt(memorywidth) + 8 + "px"
    if (persistlastviewedmsg && get_cookie("lastscrollerpos") != "")
        revivelastmsg()
    memoryscroller.innerHTML = memorycontent
    actualwidth = document.all ? temp.offsetWidth : document.getElementById("temp").offsetWidth
    lefttime = setInterval("scrollmarquee()", 20)
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = ""
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1)
                end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}

function savelastmsg() {
    document.cookie = "lastscrollerpos=" + memoryscroller.style.left
}

function revivelastmsg() {
    lastscrollerpos = parseInt(get_cookie("lastscrollerpos"))
    memoryscroller.style.left = parseInt(lastscrollerpos) + "px"
}

if (persistlastviewedmsg && persistmsgbehavior == "onload")
    window.onunload = savelastmsg

function scrollmarquee() {
    if (parseInt(memoryscroller.style.left) > (actualwidth * (-1) + 8))
        memoryscroller.style.left = parseInt(memoryscroller.style.left) - copyspeed + "px"
    else
        memoryscroller.style.left = parseInt(memorywidth) + 8 + "px"
}

if (iedom) {
    with (document) {
        document.write('<table border="0" cellspacing="0" cellpadding="0" style="' + combinedcssTable + '"><td>')
        write('<div style="position:relative;overflow:hidden;' + combinedcss + '" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=memoryspeed">')
        write('<div id="memoryscroller" style="position:absolute;left:0px;top:0px;" ' + divonclick + '></div>')
        write('</div>')
        document.write('</td></table>')
    }
}

所以我尝试更改变量,但没有任何效果。我希望你能帮忙!

谢谢!

4

2 回答 2

2

您不应该包含两次脚本调用,即使您想运行滚动器两次或可能多次,您也应该只调用一次脚本。发布此内容时,无论何时您想使用滚动条,您都应该使用事件调用该方法。您应该使用 onSubmit/onblur 等方法调用绑定事件。

于 2013-11-04T14:16:31.070 回答
1

如果您正在学习 javascript,则应该了解所有这些函数的作用。

这个脚本确实使用了 SOME 标识符两次。所以可能的情况是:函数名、var 名和 html dom id。

如果你想学习 javascript,你应该明确地检查一下这个东西是如何工作的并自己做。此外,这是一些非常糟糕的代码。您永远不应该在 javascript 文件中定义网站的内容

给你一个小小的启动:

lefttime = setInterval("scrollmarquee()", 20)

该行设置了一个计时器。scrollmarquee() 在 20 毫秒内被调用。

memoryscroller.style.left = someVar

此行设置左侧的 css 样式。这是内存滚动条的位置。您可以增加此位置以实现滚动效果。

在这里,您需要一些心态来完成您正在尝试做的事情:您在开始时调用一次 scrollmarquee。然后增加滚动元素的位置。然后,您再次使用 scrollmarquee 调用“setInterval”方法。所以 scrollmarquee 每 20 毫秒调用一次。

于 2013-11-04T14:19:26.797 回答