首页 > 代码库 > 一段滚动文字的js (jQuery)

一段滚动文字的js (jQuery)

 function startmarqueeOneSMS() {                    var t;                    var to;                    var ishover = false;                    var waitone = 3000;                    var speed = 30;                    var currentI = 0;                    var stop_margintop = {};                    var o = document.getElementById("demo2");                    var maxI = jQuery("div", o).length;                    var tempmargintop = 0;                    jQuery("div", o).each(function(index) {                        tempmargintop += jQuery(this).outerHeight();                        stop_margintop[index] = tempmargintop;                    });                    //复制一份避免出现空白                    o.innerHTML += o.innerHTML;                    o.style.marginTop = "0px";                    function start() {                        clearInterval(t);                        clearTimeout(to);                        t = setInterval(scrolling, speed);                        //document.getElementById("kw").value = http://www.mamicode.com/new Date().getSeconds();                    }                    o.onmouseover = function() {                        clearInterval(t);                        clearTimeout(to);                    }                    o.onmouseout = function() {                        start();                    }                    function scrolling() {                        var margintop = parseInt(o.style.marginTop);                        if (stop_margintop[currentI] == Math.abs(margintop)) {                            clearInterval(t);                            currentI++;                            if (currentI == maxI) {                                o.style.marginTop = "0px";                                currentI = 0;                            }                            to=setTimeout(start, waitone);                        }                        else {                            //向上滚动1PX                            o.style.marginTop = parseInt(margintop) - 1 + "px";                        }                    }                    start();                }                startmarqueeOneSMS();            });

在原来的一直滚动稍微改了一下,每滚动一条之后停一会儿。

一段滚动文字的js (jQuery)