Click to See Complete Forum and Search --> : static button location


bxc3518
12-23-2002, 01:05 PM
I need to find code to allow a button to remain in a constant location within the page, even after window is resized or has been scrolled. Can someone help me?

Zach Elfers
12-23-2002, 01:09 PM
position the button absolutely.

<input type="button" style="position:absolute;left:0px;top:0px;">

bxc3518
12-23-2002, 01:14 PM
Thank you Zach!

Zach Elfers
12-23-2002, 01:14 PM
Your welcome!

khalidali63
12-23-2002, 01:24 PM
thats only one p[art of the solution.You have to update the buttons position according to the new visible location on the page continously

Khalid

Zach Elfers
12-23-2002, 01:30 PM
huh?!?!?!?!

bxc3518
12-23-2002, 02:50 PM
khalidali63,

How do I code that?

khalidali63
12-23-2002, 03:41 PM
the code below wil work with IE and NS/MOZILLA 6+ browsers

<script language="JavaScript1.2">
var winH = 0;
var winW = 0;

var winYOffset = 0;
var winXOffset = 0;

function positionButton(){
var btn = document.getElementById("sb").style;
if (!document.all && document.getElementById){
winH = window.innerHeight;
winW = window.innerWidth;
winYOffset = window.pageYOffset;
winXOffset = window.pageXOffset;
}else if(document.all){
winH = document.body.clientHeight;
winW = document.body.clientWidth;

winYOffset = document.body.scrollTop;
winXOffset = document.body.scrollLeft;
}
//set new position for the button
btn.top = ((winH/6)+winYOffset);
btn.left =(winW/2)+winXOffset;
}

document.onmousemove = positionButton;

</script>
</head>
<body onload="positionButton();">

<div id="sb" style="position:absolute;">
<input type="Button" value="Static Button"></input>
</div>

Khalid

khalidali63
12-23-2002, 03:42 PM
crap, I forgot to write window resize function..

:-)

Khalid

khalidali63
12-23-2002, 03:50 PM
ok the above code will work with window resizing as well,but it is probably not optimised..


:-)

Khalid