温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

js实现走马灯效果-----大屏幕滚动抽奖

发布时间:2020-06-30 07:32:16 来源:网络 阅读:1256 作者:quyunde 栏目:web开发

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
        var intervalOne = null;
        window.onload = function() {
            let arr = [
                "@------四等奖---",
                "@------二等奖---",
                "@------三等奖---",
                "@------再来一次---",
                "@------一等奖---",
                "@------三等奖---",
                "@------四等奖---",
                "@------四等奖---",
                "@------再来一次---",
                "@------四等奖---"
            ];
            show(arr);
            intervalOne = setInterval(function() {
                scroll();
            }, 10);
        }

        function show(arr) {
            for(item in arr) {
                let inner_div = document.createElement("div");
                inner_div.id = "item" + item;
                inner_div.style.height = "40px";
                inner_div.style.backgroundColor = item % 2 == 0 ? "#B9E3FB" : "#FFFFCC";
                inner_div.innerText = arr[item];
                inner_div.onclick = function() {
                    document.getElementById("show_data").innerText = "中奖情况:" + inner_div.innerText;
                }
                let out_div = document.getElementById("out_div");
                out_div.appendChild(inner_div);
            }
        }

        function scroll() {
            let scrollTop = document.getElementById("out_div").scrollTop;
            document.getElementById("out_div").scrollTop = scrollTop + 10;
            if(39 <= scrollTop) {
                let one_inner_div = document.getElementById("out_div").firstChild;
                document.getElementById("out_div").removeChild(one_inner_div);
                document.getElementById("out_div").appendChild(one_inner_div);
            }
        }

        function mouseover1() {
            clearInterval(intervalOne);
        }

        function onmouseleave1() {
            intervalOne = setInterval(function() {
                scroll();
            }, 10);
        }

        function click1(flag) {
            debugger
            if(flag) {
                clearInterval(intervalOne);
                let one_inner_div = document.getElementById("out_div").firstChild;
                document.getElementById("show_data").innerText = "中奖情况:" + one_inner_div.innerText;
            } else {
                intervalOne = setInterval(function() {
                    scroll();
                }, 10);

            }
        }
    </script>
</head>

<body>
    <div id="out_div"  onmouseover="mouseover1()" onmouseleave="onmouseleave1()">
    </div>
    <input id="stop" type="button" value="***停***" onclick="click1(true)">
    </input>
    <input id="stop" type="button" value="***继续***" onclick="click1(false)">
    </input>
    <div id="show_data">

    </div>
</body>

</html>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI