功能:DIV相对浏览器定位及其关闭。
>html源码
<html>
<head>
<title>hello</title>
<style tyle="text/css">
html,body {
width:100%;
height:100%;
margin:0px;
padding:0px;
overflow:hidden; //溢出隐藏;解决IE8滚动条问题;
}
#Main {
position:absolute;
top:0px;
left:0px;
width:100%;
height:100%;
overflow:auto; //能显示完所有内容;
z-index:1;
}
.floatDiv {
position:absolute;
top:50px;
right:30px;
padding: 3 3 3 3;
background:#ccc;
text-align:right;
z-index:2;
}
.close {
background-color:#CC6600;
cursor: pointer;
color: #FFFFFF;
}
</style>
<script type="text/javascript" src="hello.js"></script>
</head>
<body>
<div id="Main">
First,hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
hello,world!<br />
last,hello,world!<br />
</div>
<div id="fDiv" class="floatDiv">
<div><span id="closeBtn" class="close">关闭</span></div>
<img src="img/sleep.jpg" width="200" height="150" />
</div>
</body>
</html>
>js源码
window.onload = initFn;
function initFn() {
// 关闭按钮
var closeBtn = document.getElementById("closeBtn");
closeBtn.onclick = function(){
// 浮动DIV
var floatDiv = document.getElementById("fDiv");
floatDiv.style.display = 'none'; //不显示;
}
}