Home > Web Front-end > JS Tutorial > body text

js method to achieve message scrolling effect

一个新手
Release: 2017-10-19 09:43:02
Original
1356 people have browsed it


   <div class="inform" style="">
            <div style="height:35px; overflow:hidden;">
                <ul id="marquee" style="height:35px;">
            <li><a href="javascript:void(0)" style="display:inline-block;overflow: hidden; white-space: nowrap;text-overflow:ellipsis; width: 100%;">****已预订****</a></li>
             <li><a href="javascript:void(0)" style="display:inline-block;overflow: hidden; white-space: nowrap;text-overflow:ellipsis; width: 100%;">
                                ****已预订****</a></li>
          </ul>
            </div>

            <script type="text/javascript">
                var liHeight = $(&#39;#marquee li&#39;).eq(0).outerHeight();
                //$(&#39;#marquee&#39;).css(&#39;height&#39;,liHeight * $(&#39;#marquee li&#39;).length * 2);
                setTimeout("startmarquee("+ liHeight +", 50, 500, &#39;marquee&#39;)", 500);
                function startmarquee(lh,speed,delay,id) {
                    var t;
                    var p = false;
                    var o = document.getElementById(id);
                    o.innerHTML += o.innerHTML;
                    o.onmouseover = function() {
                        p = true;
                    }
                    o.onmouseout = function() {
                        p = false;
                    }
                    o.scrollTop = 0;

                    function start() {
                        t = setInterval(scrolling,speed);
                        if(!p) o.scrollTop += 1;
                    }

                    function scrolling() {
                        if(o.scrollTop%lh != 0) {
                            o.scrollTop += 1;
                            if(o.scrollTop >= o.scrollHeight / 2) o.scrollTop = 0;
                        } else {
                            clearInterval(t);
                            setTimeout(start,delay);
                        }
                    }
                    setTimeout(start,delay);
                }
            </script>
        </div>
Copy after login
.inform {
    padding: 1px;
    margin: 10px auto;
    /*position: fixed; bottom:80px;left: 50%;*/ width: 6.8rem;font-size: 12px;/*margin-left: -3.4rem;*/ border: none; background-color:rgba(238,115,115,0.3); border-radius: 10px;
}
.inform h2 {
    background: none repeat scroll 0 0 #015198;
    font-weight: normal;
    line-height: 30px;
}
.inform h2 span {
    color: #FFFFFF;
    font-size: 16px;
    padding-left: 10px;
}
.inform h2 a {
    color: #FFFFFF;
    float: right;
    font-size: 14px;
    padding-right: 3px;
}
.inform ul {
    height: 170px;
    margin-top: 7px;
    overflow: hidden;
}
.inform ul li {
    line-height: 26px;
    padding-left: 12px;
}
Copy after login

 

The above is the detailed content of js method to achieve message scrolling effect. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!