博客首页 注册 建议与交流 排行榜 加入友情链接         宝宝相册的专门空间
推荐 投诉 搜索: 帮助

流水孟春

以前使用的博客 webvista.cublog.cn
lib.cublog.cn
js实现让层随滚动条一起滚动
尽管只用层来也能实现层随滚动条一起滚动,但是我所知道的方法必须依赖与别的层,所有直接用js实现


var tips;
var theTop = 10; /*这是默认高度,越大越往下*/
var old = theTop;

function moveTips() {
    var tt = 0;
    if (window.innerHeight) {
        pos = window.pageYOffset
    } else if (document.documentElement && document.documentElement.scrollTop) {
        pos = document.documentElement.scrollTop
    } else if (document.body) {
        pos = document.body.scrollTop;
    }

    pos = pos - tips.offsetTop + theTop;
    pos=tips.offsetTop+pos/10;
    if (pos < theTop) pos = theTop;
    if (pos != old) {
        tips.style.top = pos+"px";
        tt = 0;
    }
    old = pos;
    setTimeout(moveTips,tt);
}

onload = function initFloatTips() {
    tips = document.getElementById('clockDiv');
    moveTips();
};

发表于: 2008-01-15,修改于: 2008-01-15 23:11,已浏览411次,有评论0条 推荐 投诉

给我留言
版权所有 ChinaUnix.net 页面生成时间:0.2143