need help urgently
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: need help urgently

  1. #1
    Join Date
    Dec 2008
    Posts
    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 09:27 AM. Reason: Added code tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,839

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center