美文网首页
js实现跑马灯效果

js实现跑马灯效果

作者: xin激流勇进 | 来源:发表于2017-12-08 19:20 被阅读0次
image.png
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
        }

        #i1{
            background-color: yellow;
            color: red;
            margin: 50px auto;
            font-size: 60px;
            /*width: 350px;*/
            text-align: center;
        }

        #i2{
            position: fixed;
            width: 100px;height: 30px;
            right: 20px;
            bottom: 20px;
            background-color: #60add5;
        }
    </style>
</head>
<body>
    <div id="i1" onclick="func();">学习前端你最棒</div>

    <script>
        function func() {
            var tag = document.getElementById('i1');
            var content = tag.innerText;
            var first = content.charAt(0);
            var last = content.substring(1, content.length);
            tag.innerText = last + first;
        }
        setInterval('func()', 1000);
    </script>
</body>
</html>

相关文章

网友评论

      本文标题:js实现跑马灯效果

      本文链接:https://www.haomeiwen.com/subject/wzkyixtx.html