J
jidixuelang
Hi all!
I create a div ,which i wish can stay top alway?I user onscroll to
simulate this.
But let me desponding,when scroll down the scrollbar,i can see the div
is faltering distinctly!
Is there any method I can use to avoid the falter?
Please look the following code:
I create a div ,which i wish can stay top alway?I user onscroll to
simulate this.
But let me desponding,when scroll down the scrollbar,i can see the div
is faltering distinctly!
Is there any method I can use to avoid the falter?
Please look the following code:
Code:
<!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=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html,body{ margin:0;}
#topDiv {
width:100%;
height:80px;
background:#ccc;
color:#fff;
font-size:24px;
font-weight:bold;
text-align:center;
}
</style>
</head>
<body>
<div id="topDiv">Is there any method I can avoid the falter when i
scroll down the scrollbar?</div>
<script type="text/javascript">
function autoScrollDiv(id){
this.dbody = document.getElementById(id);
with(this.dbody.style){
position= "absolute";
top = "0";
left = "0";
}
var control = this.dbody;
window.onscroll = function(){
var posY = document.documentElement.scrollTop ||
document.body.scrollTop;
control.style.top = posY + "px";
}
}
/*
autoScrollDiv.prototype = {
autoScroll:function(){
var posY = document.documentElement.scrollTop ||
document.body.scrollTop;
this.dbody.style.top = posY + "px";
}
}
*/
var a = new autoScrollDiv("topDiv");
</script>
[QUOTE]
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /
<br /><br /><br />[/QUOTE]
</body>
</html>