码迷,mamicode.com
首页 > Web开发 > 详细

一段滚动文字的js (jQuery)

时间:2014-09-05 23:38:02      阅读:417      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   art   div   cti   sp   

 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 = 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)

标签:style   blog   color   io   ar   art   div   cti   sp   

原文地址:http://www.cnblogs.com/zzjj296/p/3958846.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!