Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1313 How can I move a layer all the time across the screen from right to left and back?

You are here: irt.org | FAQ | DHTML | Q1313 [ previous next ]

Try:

<html>

<head>
<script language="JavaScript"><!--
var xInc = 10, yInc = 10, xMax = 0;

function startToMoveIt() {
    if (document.all)
        xMax = document.body.offsetWidth;
    else if (document.layers)
        xMax = window.innerWidth - document.myLayer.document.width;
    if (document.all || document.layers)
        moveit();
}

function moveit() {
    if (document.all)
        xNew = document.all('myLayer').style.posLeft + xInc;
    else if (document.layers)
        xNew = document.myLayer.left + xInc;

    if (xNew < xMax && xNew >=0) {
        if (document.all)
            document.all('myLayer').style.posLeft = xNew;
        else
            if (document.layers) document.myLayer.left = xNew;
    }
    else
        xInc = xInc * (-1);

    setTimeout("moveit()",75);
}
//--></script>
</head>

<body onLoad="startToMoveIt()">

<div id="myLayer" style="position: absolute; top: 0; left: 0;">
Some Text
</div>

</body>
</html>

©2018 Martin Webb