简体   繁体   中英

JavaScript Div scroller does not work in chrome

I have a JavaScript scroller that's working in IE but not working in Chrome. Also, is there a way to expand this script to stop or restart from the stop? It is scrolling infinitely.

The JavaScript:

// JavaScript Document
var scrollspeed = "1"       // SET SCROLLER SPEED 1 = SLOWEST
var speedjump       = "30"  // ADJUST SCROLL JUMPING = RANGE 20 TO 40
var startdelay  = "2"   // START SCROLLING DELAY IN SECONDS
var nextdelay       = "5"   // SECOND SCROLL DELAY IN SECONDS 0 = QUICKEST
var topspace        = "0"       // TOP SPACING FIRST TIME SCROLLING
var frameheight = "277" // IF YOU RESIZE THE WINDOW EDIT THIS HEIGHT TO MATCH

current = (scrollspeed)

if (isIE) {     

    function HeightData(){
        AreaHeight=dataobj.offsetHeight
        if (AreaHeight==0){
            setTimeout("HeightData()",( startdelay * 1000 ))
        } else {
            ScrollNewsDiv()
        }
    }

    function NewsScrollStart(){
        dataobj=document.all? document.all.ticker :      document.getElementById("ticker")
        dataobj.style.top=topspace
        setTimeout("HeightData()",( startdelay * 1000 ))
    }

    function ScrollNewsDiv(){
        dataobj.style.top = (parseInt(dataobj.style.top) - (scrollspeed)) + "px";
        if (parseInt(dataobj.style.top)<AreaHeight*(-1)) {
            dataobj.style.top=frameheight
        setTimeout("ScrollNewsDiv()",( nextdelay * 1000 ))
        } else {
            setTimeout("ScrollNewsDiv()",speedjump)
        }
    }

    NewsScrollStart();
}

And the HTML:

<body onload="ScrollNewsDiv();">
<div id="ticker" style="display: block;">
    content
</div>

Perhaps a naive answer but I will go for it.

Because all the functions are conditioned on isIE which is, presumably, false in Chrome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM