Home > Web Front-end > JS Tutorial > js case marquee code

js case marquee code

零下一度
Release: 2017-07-20 17:13:07
Original
1705 people have browsed it

The specific code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
            font-size:14px;
        }
        #box{
            margin:50px auto;
            padding:0 10px;
            width:1000px;
            height:35px;
            line-height:35px;
            border:1px dashed green;
            background:lightgreen;
        }
        #box #wrap{
            height:35px;
            overflow:hidden;
            white-space:nowrap;
        }
        #box span{
            color:red;
            font-weight:bold;
            font-size:16px;
        }
        #wrap div{
            display:inline-block;
        }</style>
</head>
<body>
    <div id=&#39;box&#39;>
        <div id=&#39;wrap&#39;>
            <div id=&#39;conBegin&#39;>
                <span>通知:</span>7月6日消息,今日下午人民日报在微博上发表了一篇名为《新闻莫被算法"绑架"》的文章,文中直指"今日头条""一点资讯"这类痴迷于技术和算法的新闻客户端越来越'简单粗暴'了,并批判这些公司引.文中直指"今日头条""一点资讯"这类痴迷于技术和算法的新闻客户端越来越'简单粗暴'了,并批判这些公司引
            </div>
            <div id=&#39;conEnd&#39;>
                <span>通知:</span>7月6日消息,今日下午人民日报在微博上发表了一篇名为《新闻莫被算法"绑架"》的文章,文中直指"今日头条""一点资讯"这类痴迷于技术和算法的新闻客户端越来越'简单粗暴'了,并批判这些公司引.文中直指"今日头条""一点资讯"这类痴迷于技术和算法的新闻客户端越来越'简单粗暴'了,并批判这些公司引
            </div>
        </div>
        
    </div>

    <script>
        ~function(){var box = document.getElementById('box');var conBegin = document.getElementById('conBegin');var wrap = document.getElementById('wrap');var conBegin_width = getCss(conBegin,'width');//之前封装好的获取css样式的方法var timer = window.setInterval(move,10)function move(){//优化前的代码// var curLeft = wrap.scrollLeft;// wrap.scrollLeft = curLeft +1;// var newLeft = wrap.scrollLeft;// if(curLeft == newLeft){// //利用了scrollLeft是存在最大值的思想,在累加1之前获取一个值,在累加之后获取一个值,如果两个值相等了,说明已经达到最大值了,所以清除定时器//     // window.clearInterval(timer)//     wrap.scrollLeft = 0//这样虽然从头开始了,但是会导致会闪烁一下。// }//优化后的代码  使用两个一样内容的div避免闪烁wrap.scrollLeft++;var curLeft = wrap.scrollLeft;if(wrap.scrollLeft >= conBegin_width){
                    wrap.scrollLeft = 0}
            }//鼠标划过停止box.onmouseover = function(){
                window.clearInterval(timer);
            }
            box.onmouseout = function(){
                timer = window.setInterval(move,10)
            }
        }()        </script>
</body>
</html>
Copy after login

The above is the detailed content of js case marquee code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template