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();
};

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM