例子:屏幕右侧悬浮框
原理:oDiv.style.top = document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop + “px”;
浏览器窗体的高度
document.documentElement.clientHeight
浏览器滚动的高度
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
html内容区
<body style=" height:1600px;">
<div id="div1"></div>
</body>
#div1 { position:absolute; right:0; bottom:0; width:100px; height:150px; background:green;}
js内容区
<script>
window.onscroll = function(){
var oDiv = document.getElementById("div1");
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
//oDiv.style.top = document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop + "px&#