<!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>scroll</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
height:2000px;
}
</style>
<script type="text/javascript">
window.onload = function () {
var cs = document.getElementById('cs'), pf = document.getElementById('pf');
if (cs.attachEvent)
cs.attachEvent('onmousewheel', scrollMove);
else if (cs.addEventListener) {
cs.addEventListener('DOMMouseScroll', scrollMove, true);
}
cs.scrollTop = 0;
pf.style.height = Math.max(cs.clientHeight / cs.scrollHeight * cs.clientHeight, 6) + 'px';
cs = pf = null; //非必要
};
var scrollMove = function (e) {
var e = window.event || e, o = e.srcElement || e.target, d = -e.wheelDelta || e.detail;
o.scrollTop = o.scrollTop + d / Math.abs(d) * Math.floor(o.clientHeight * 0.15);
document.getElementById('pf').style.top = 51 + Math.round(o.scrollTop / o.scrollHeight * o.clientHeight) + 'px';
e.stopPropagation && (e.preventDefault(), e.stopPropagation()) || (e.cancelBubble = true, e.returnValue = false); //取消默认滚动
};
</script>
</head>
<body>
<div id="cs" style="margin-top:50px;width:500px;height:200px; overflow:hidden; border:#000000 1px solid;">
<script type="text/javascript">
!function () {
for (var i = 0, a = [] ; i < 201 ; i ++) a[i] = i;
document.write(a.join('<br \/>'));
}();
</script>
</div>
<div id="pf" style="position:absolute;left:481px;top:50px; width:20px; height:10px;font-size:10px; background-color:#6699CC; border:#CCCCCC 1px solid;"> </div>
</body>
</html>