-
December 2nd, 2008, 09:20 AM
#1
need help urgently
Hi all,
I am new to JavaScript. i am making a page which shoud have a div floating. i changed the position to fixed which solved it but now i want to change the position to the absolute on condition that when the scrolling div comes to a certain area i can change it is that consider the code
Code:
<div id="container" >
<DIV id="formButtons"><asp:Button id="Button1" onclick="Button1_Click" runat="server" BackColor="Aqua" Width="201px" Text="Save Form"></asp:Button> </DIV></div>
the div container is the parent div with height 500px and div formButtons is the scrolling div
i want scroling div to move in the parent div is that if i scroll to the bottom the scrolling div should stick on the bottom of the container div
the javascript i used for this is as follows it works but the problem is i am using constant values it will work if the window is of specific size is there any way to get the end position of the parent div
Code:
window.onscroll = function()
{
if (document.documentElement.scrollTop < "530") //the value i have putten in quatation is the constant where i need a certain function to dynamicaly get the values the value entered here is one where i want div to stick but it changes when maximized
{
document.getElementById("formButtons").style.position= 'fixed';
document.getElementById("formButtons").style.bottom= '0px';
document.getElementById("formButtons").style.right= '0px';
}
else
{
document.getElementById("formButtons").style.position='absolute';
document.getElementById("formButtons").style.right='0px';
document.getElementById("formButtons").style.bottom="'-690px'"; the value here should also be assigned dynamically on parent container bottom right
}
}
what should i do please Help?
Last edited by PeejAvery; December 2nd, 2008 at 10:27 AM.
Reason: Added code tags.
-
December 2nd, 2008, 10:33 AM
#2
Re: need help urgently
I'm sorry, but I am having a difficult time understanding your English.
Can't you just add the start y coordinate of your div to the height of the div? That will give you the exact y coordinate of the botton of the div.
Code:
var obj = document.getElementById('YOUR_DIV_ID');
if (obj.offsetParent) {
var y = obj.offsetTop;
var h = obj.offsetHeight;
while (obj = obj.offsetParent) {
y += obj.offsetTop;
}
}
var bottom = y + h;
alert(bottom); // this should return the bottom y coordinate of your div
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|