文字滚动

function scroll(obj) {
/*往左*/
var tmp = (obj.scrollLeft)++;
//当滚动条到达右边顶端时
if (obj.scrollLeft == tmp) {
obj.innerHTML += obj.innerHTML;
}
//当滚动条滚动了初始内容的宽度时滚动条回到最左端
if (obj.scrollLeft >= obj.firstChild.offsetWidth) {
obj.scrollLeft = 0;
}

/*往上*/
//var tmp = (obj.scrollTop)++;
//if (obj.scrollTop == tmp) {
// obj.innerHTML += obj.innerHTML;
//}
//if (obj.scrollTop >= obj.firstChild.offsetWidth) {
// obj.scrollTop = 0;
//}
}
var _timer = setInterval("scroll(document.getElementById('scrollobj'))", 20);
function _stop() {
if (_timer != null) {
clearInterval(_timer);
}
}
function _start() {
_timer = setInterval("_scroll(document.getElementById('scrollobj'))", 20);
}


//公告字幕滚动
function scrollTxt($obj){
    $obj.each(function(){
        var $this = $(this);
        var $span = $this.find("span");
        if($this.width() < $span.width())
        {
            $(this).append($span.clone());
            timer=setInterval(function(){mar($this,$span)},30);
        }    
    })
}

function mar($this,$span){
    if($span.width() <= $this.scrollLeft()){
        $this.scrollLeft($this.scrollLeft()-$span.width());
    }else{
        $this.scrollLeft($this.scrollLeft()+1);
    }
}

 

posted @ 2015-09-09 17:56  hpyou  阅读(270)  评论(0编辑  收藏  举报