javascript控制网页某元素浮动js代码

作者:freethy 发布于:2013-1-21 12:56 Monday

//先设置网页某元素位置为绝对定位

var lastScrollY=0;

function heartBeat(){
    var diffY=document.body.scrollTop;
    var percent=0.1*(diffY-lastScrollY);
    if(percent>0) percent=Math.ceil(percent);
    else percent=Math.floor(percent);

    lastScrollY=lastScrollY+percent;

    //设置网页元素距离顶部高度

    img.style.top = lastScrollY;
}
window.setInterval("heartBeat()",1);

Powered by emlog 苏ICP备11068260号-7