Results 1 to 2 of 2

Thread: Getting position & visibility of an element

  1. #1
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Getting position & visibility of an element

    Hi,

    I'm working on a site that has a resizable div. On 2 of the pages, elements within that container div should become invisible (rather than scrolling or cropping) if they are not completely within the visible area of the container.

    I've got a function that uses offsetTop and offsetHeight to figure out if each child is within bounds, and toggles the visibility property. It works in firefox, but not in IE.

    Can anyone see what I'm doing wrong here? Is there a better way to do this?

    Thanks!
    -Ann

    Test page:
    http://indigopear.com/Clients/vanduuren/Portfolio.php

    And here's the script:

    // Set height of contentPanel
    //
    y = y-196-50;
    var panel=document.getElementById('contentPanel');
    panel.style.height = y + 'px';
    //
    //
    // Set visibility of child elements in contentPanel
    //
    function setVisibility(node, y, panel) {
    var children=node.childNodes;
    for (var i=0; i < children.length; i++) {
    if (children[i].className && (children[i].className == 'toggle' || children[i].className.search('toggle'))) {
    var parent = children[i].offsetParent;
    var top = children[i].offsetTop;
    var height = children[i].offsetHeight;
    alert("offsetTop = " + top + " offsetHeight = " + height + " panel height = " + y + " panel offsetTop = " + panel.offsetTop);
    if ( (top+height) > (y+panel.offsetTop) )
    children[i].style.visibility = 'hidden';
    else
    children[i].style.visibility = 'visible';
    }
    else
    setVisibility(children[i], y, panel);
    }
    }
    if (panel.className == 'noScroll') {
    panel.style.overflow = 'hidden';
    setVisibility(panel, y, panel);
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm having a little trouble following all this but, your typical scrollHeight for one of the toggle class objects is 22 in FF 162 in IE, that could be a problem.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •