SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript - Prevent absolutely positioned ttems from overlapping if window too small

    I want to use Javascript to prevent absolutely positioned items from overlapping if the window too small. I adapted the following script from other pages on the web that approximated what I want to accomplish:

    Code:
    function fnPCL() {
    	var iContentHeight, iAvailableHeight;
    	
    	eCopyright.style.position = "static";
    	iContentHeight = document.body.scrollHeight;
    	iAvailableHeight = document.body.offsetHeight;
    
    	if(iContentHeight <= (iAvailableHeight - 25)){
    		eCopyright.style.position = "absolute";
    		eCopyright.style.top = "auto";
    		eCopyright.style.bottom = "0px";
    	}else{
    		eCopyright.style.position = "static";
    	}
    	eCopyright.style.display = "block"
    	window.status = "contentHeight=" + iContentHeight + ", AvailableHeight=" + iAvailableHeight + ", position=" + eCopyright.style.position
    }
    Here is a demo page that I made for the script (works in Internet Explorer). If the window is large enough the the text will be placed at the bottom of the page. Otherwise it will placed inline with the document. Try resizing the page so that it's both a very small window and a very large one to see how it works.

    The problem that I'm having is that the script doesn't always work. At times it appears to be getting an incorrect (too large) value for the height of the cotnent and as such the text at the bottom isn't absolutely positioned the way it should be. Additionally, my script doesn't work on Netscape6. Any suggestions about imporving this script. Or if you know of a working example of what I'm trying to do, please point me to it.

    Cheers!

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi prowsej,

    I haven't bothered with NN 6 yet, so I can only point you to a direction...In all likelihood, "document.body.scrollHeight" is non-standard. If you already haven't found the solution to your problem, post it at the JSCity javascript forum (link in my sig) ask for aDog's help. He's one of the resident NN6 experts.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    SitePoint Addict
    Join Date
    Jan 2001
    Location
    Ottawa ON
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reference to the JSCity forums - they're an excellent resource, but they're certain well hidden away (searching Google for JSCity barely produces a single hit!) I'll take my question over there.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •