<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> body{ height:2000px; } #box{ width: 300px; height:300px; position: absolute; background-color: #8c8c8c; } </style><script>window.onload = function(){function pop (){ var scrollTop = document.body.scrollTop;//滚动条到顶部 var oBox = document.getElementById('box'); var oClose = document.getElementById('close'); oBox.style.display = 'block'; oBox.style.top=document.documentElement.clientHeight/2-oBox.offsetHeight/2+scrollTop+'px'; oBox.style.left=document.documentElement.clientWidth/2-oBox.offsetWidth/2+'px'; }pop(); } </script></head><body> <div id="box"></div></body></html>
3 回答
添加回答
举报
0/150
提交
取消