第一篇帖子,就弄个JS动态公告浏览吧,直接上代码

.scroll{
    margin-left:45px;
    margin-top:-150px;
    height:100px;
    width:300px;
}

<script language="JavaScript">
function addEventSimple(obj,evt,fn){
    if(obj.addEventListener){
        obj.addEventListener(evt,fn,false);
    }else if(obj.attachEvent){
        obj.attachEvent('on'+evt,fn);
    }
}

addEventSimple(window,'load',initScrolling);

var scrollingBox;
var scrollingInterval;
var reachedBottom=false;
var bottom;

function initScrolling(){
    scrollingBox = document.getElementById('xst');
    scrollingBox.style.overflow = "hidden";
    scrollingInterval = setInterval("scrolling()",50);
    scrollingBox.onmouseover = over;
    scrollingBox.onmouseout = out;
}

function scrolling(){
    var origin = scrollingBox.scrollTop++;
    if(origin == scrollingBox.scrollTop){
        if(!reachedBottom){
            scrollingBox.innerHTML+=scrollingBox.innerHTML;
            reachedBottom=true;
            bottom=origin;
        }else{
            scrollingBox.scrollTop=bottom;
        }
    }
}

function over(){
    clearInterval(scrollingInterval);
}
function out(){
    scrollingInterval = setInterval("scrolling()",50);
}

</script>

<div class="scroll" id="xst" style="font-size:14px">

<p><a href=""></a></p>

上一篇:node.js处理post请求


下一篇:JS string 截取