Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Determining if an element is visible
Old 03-22-2006, 05:22 PM Determining if an element is visible
Junior Talker

Posts: 2
Trades: 0
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 mozilla, but not in IE.

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

Thanks!
-Ann

Test pages:
http://indigopear.com/Clients/vanduuren/Home.php
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);
}
indigopear is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2006, 07:44 PM Re: Determining if an element is visible
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,520
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
simply using

container {
overflow:hidden;
}

would work for me I think
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2006, 09:52 PM Re: Determining if an element is visible
Junior Talker

Posts: 2
Trades: 0
Thanks for the reply, Chris. Setting overflow:hidden will simply crop any elements that don't fit in the container - the behavior we're after is to have cropped elements disappear altogether. The part I'm having trouble with is determining if a child element is getting cropped. ..

Thanks,
-Ann
indigopear is offline
Reply With Quote
View Public Profile
 
Old 03-23-2006, 12:44 AM Re: Determining if an element is visible
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
I'm not sure if this is it, but I've noticed that in IE you need to explicity use var whenever first defining a variable. Seems like you do that everywhere except at the top for y = y-196-50;

I'm grasping I think, but also hoping that those 3 letters out front might fix things in IE.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Reply     « Reply to Determining if an element is visible
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.82224 seconds with 12 queries