F
faylau
Hi,
I copied some javascript code off of this group to keep a banner in
view as the user scrolls down the page. The code works fine in Firefox
and Netscape but not in IE. Just wondering if someone can tell me what
I need to change in the code to get it to work as universally as
possible. I don't know javascript and usually just copy code snippets
without really know what's going on. Hopefully this should be simple
for someone who actually knows what's going on.
Here's the code:
<html>
<head>
<title>Gluing banneer</title>
<style type="text/css">
#banneer{
background-color:yellow;
color:red;
border:thin outset;
width:150px;
position:absolute;
}
</style>
<script type="text/javascript">
function f(){
var div_top=0;
var win_top=0;
var x=1;
var div=document.getElementById("banneer");
var ypos=0;
if(div.style.top=="")div.initialTop=div.offsetTop;
win_top=div_top=div.offsetTop;
if(document.body.scrollTop!=undefined){
win_top=document.body.scrollTop;
x=3;
}else if(window.pageYOffset!=undefined){
win_top=window.pageYOffset;
x=6;
}
ypos=(win_top+div.initialTop-div_top)/x+div_top;
div.style.top=(ypos)+"px";
}
//The banneer follows!
setInterval("f()",10);
</script>
</head>
<body>
<div id="banneer">Hello World</div>
<div style="height:2000px"></div>
</body>
</html>
Thanks.
I copied some javascript code off of this group to keep a banner in
view as the user scrolls down the page. The code works fine in Firefox
and Netscape but not in IE. Just wondering if someone can tell me what
I need to change in the code to get it to work as universally as
possible. I don't know javascript and usually just copy code snippets
without really know what's going on. Hopefully this should be simple
for someone who actually knows what's going on.
Here's the code:
<html>
<head>
<title>Gluing banneer</title>
<style type="text/css">
#banneer{
background-color:yellow;
color:red;
border:thin outset;
width:150px;
position:absolute;
}
</style>
<script type="text/javascript">
function f(){
var div_top=0;
var win_top=0;
var x=1;
var div=document.getElementById("banneer");
var ypos=0;
if(div.style.top=="")div.initialTop=div.offsetTop;
win_top=div_top=div.offsetTop;
if(document.body.scrollTop!=undefined){
win_top=document.body.scrollTop;
x=3;
}else if(window.pageYOffset!=undefined){
win_top=window.pageYOffset;
x=6;
}
ypos=(win_top+div.initialTop-div_top)/x+div_top;
div.style.top=(ypos)+"px";
}
//The banneer follows!
setInterval("f()",10);
</script>
</head>
<body>
<div id="banneer">Hello World</div>
<div style="height:2000px"></div>
</body>
</html>
Thanks.