js无间断滚动新闻js.支持火狐和IE

来源:互联网 发布:网络学习平台 编辑:程序博客网 时间:2024/06/03 11:18


var container = null;
var clone = null;
var rollingTop = function() {
    //alert(container.scrollTop + "=-===" + clone.offsetTop);
    if (container.scrollTop == clone.offsetTop) {
        container.scrollTop = 0;
    } else {
        container.scrollTop++;
    }
}
var rollingBottom = function() {
    if (container.scrollTop == 0) {
        container.scrollTop = clone.offsetTop;
    } else {
        container.scrollTop--;
    }
}
var rollingLeft = function() {
    if (container.scrollLeft == clone.offsetLeft) {
        container.scrollLeft = 0;
    } else {
        container.scrollLeft++;
    }
}

var rollingRight = function() {
    if (container.scrollLeft == 0) {
        container.scrollLeft = clone.offsetLeft;
    } else {
        container.scrollLeft--;
    }
}
//top JS

function Marquee(id, speed, type) {
    container = document.getElementById(id);
    original = document.getElementById("default");
    clone = document.getElementById("inner")

    clone.innerHTML = original.innerHTML;
    var functionTag = null;
    if (type == "Up") {
        functionTag = rollingTop;
    }
    else if (type == "Down") {
        functionTag = rollingBottom;
    }
    else if (type == "Left") {
        SetLeftCss(original, clone);
        functionTag = rollingLeft;
    }
    else if (type == "Right") {
        SetLeftCss(original, clone);
        functionTag = rollingRight;
    } else { return; }
    var timer = setInterval(functionTag, speed); //设置定时器
    container.onmouseover = function() { clearInterval(timer) } //鼠标移到marquee上时,清除定时器,停止滚动
    container.onmouseout = function() { timer = setInterval(functionTag, speed) } //鼠标移开时重设定时器
}

function SetLeftCss(obj, obj1) {
    obj.style.styleFloat = "left";
    obj1.style.styleFloat = "left";
    obj.style.cssFloat = "left";
    obj1.style.cssFloat = "left";
    obj.style.width = "400px";
    obj1.style.width = "400px";
}

net自定义控件中调用方法:

const string KEY="SSSSCROLLNEWS";
                if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(),KEY))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), KEY, string.Format("<script>Marquee('SSS{0}', {1}, '{2}');</script>", divId, this.Speed, this.Direction
                        .ToString()));
                }

原创粉丝点击