8.7w+
社区成员
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.float
{
position: fixed;
left:20px;
top:30px;
width:100px;
height:30px;
background-color: Silver;
}
.long
{
height: 2000px;
}
</style>
</head>
<body>
<div id="floatDiv" class="float">
测试内容
</div>
<div class="long"></div>
</body>
</html>
<script type="text/javascript">
var userAgent = navigator.userAgent.toLowerCase();
var browser = {
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1]
};
var div = document.getElementById('floatDiv');
if (browser.msie && browser.version < 8) {
div.style.position = 'absolute';
var offsetTop = document.getElementById('floatDiv').offsetTop;
window.onscroll = function() {
var top = document.documentElement.scrollTop + offsetTop;
document.getElementById('floatDiv').style.top = top;
};
}
</script>