HTML:防止选框区域为空?

时间:2012-07-02 08:07:05

标签: html marquee

有一个大帐篷上升。 当文本滚动完成(再次出现之前)时,选取框区域会变空并持续约2秒钟,然后再次恢复。

有没有办法防止它变空,并且在最后一行上升之前让第一行出现?

http://jsfiddle.net/WArVQ/2/

1 个答案:

答案 0 :(得分:0)

您可以使用JavaScript执行此操作:

<!DOCTYPE html>
<html>
<head>
    <title>Scroll demo</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <div id="container" style="position: absolute; width: 200px; height: 200px; background-color: grey">
    </div>
    <script type="text/javascript">
        var maxy = 200; // adjust
        var lineHeight = 17; // adjust
        var lines = new Array("line1", "line2", "line3");
        var textDivs = new Array(lines.length);
        for(var i=0;i<lines.length;i++) {
            var divx = document.createElement("div");
            var divxText = document.createTextNode(lines[i]);
            divx.style.top=String(maxy-(lines.length-i)*lineHeight)+"px";
            divx.style.position="absolute";
            divx.appendChild(divxText);
            textDivs[i] = divx;
            document.getElementById("container").appendChild(divx);
        }

        window.setInterval("scroll()", 50);
        function scroll() {
            for(var i=0;i<textDivs.length;i++) {
                var divx = textDivs[i];
                var y = parseInt(divx.style.top);
                y = y-1;
                if(y<0) y = maxy-lineHeight;
                divx.style.top =String(y)+"px";
            }
        }
    </script>
</body>
</html>