天天看点

让一个DIV在页面右边并跟随滚动条移动

function getScroll() { var top, left, width, height; if (document.documentElement && document.documentElement.scrollTop) { top = document.documentElement.scrollTop; left = document.documentElement.scrollLeft; width = document.documentElement.scrollWidth; height = document.documentElement.scrollHeight; } else if (document.body) { top = document.body.scrollTop; left = document.body.scrollLeft; width = document.body.scrollWidth; height = document.body.scrollHeight; } return { top: top, left: left, width: width, height: height }; } function scall(){ var v = getScroll(); //alert(v.top); var e = document.getElementById("float_right"); e.style.top = ((v.top) + 50) + "px"; //纵滚动条离顶部距离 } window.onload = scall ; window.onscroll = scall ;