As a result of a previous thread, I started some programming with Javascript.
I’d like to use it to expand/collapse some headers in a page.
I made following code to do this.:
That works perfect!
But I want to add something, and I have some problems with that. As I have e.g. 4 headers, I want to expand the text (in <p>-tag) by clicking on header 1. When I click on header 2, I want to collapse text of header 1 and expand header 2 text.
And so on.
That way, I get the height of the site relatively small without needing to scroll.
I don’t quite know how to implement this function into my JS-code!
And if it could be implemented in my .js file, how do I link that in my html, because now I have in every header the same line:
<a href=“#first” onClick=“shoh(‘first’);”>, <a href=“#second” onClick=“shoh(‘first’);”>, etc…
Maybe an extra question: How can I get the content of header 1 be seen as soon as the screen pops up. So you don’t have to click on Header1 before you can see it? And then go on from there: clicking on header2 makes text of header 1 disappear and expands text from header 2, and so on…
if(me_height <= 40)
{
busy_sliding = false;
clearInterval(timer_id_close);
}
}
var busy_sliding = false;
var timer_id_open;
var timer_id_close;
function start_slide(me_id)
{
var me_obj = document.getElementById(me_id);
var me_height = parseInt(me_obj.style.height);
var div_elems=document.getElementsByTagName(“div”);
for(var i = 0; i < div_elems.length; i++)
{
var tempstr = div_elems[i].id;
if(tempstr.search(‘_’) == -1)
{
if((div_elems[i].id != me_id)&&(div_elems[i].id != “”))
{
var obj = document.getElementById(tempstr);
var height = parseInt(obj.style.height);
var top = parseInt(obj.style.top);
Thanks for the answer, but actually that won’t work so good, since I work within a table.
my <h3>-tag is the header, which needs to be clicked, and the <p>- tag is the content that should collapse/expand.
So I can’t really give a height to those two tags…
But I sure did like the idea.
I’m a bit worried about my layout in the table and overall, if I put divs in it to make it work like your idea…
Maybe something easier for code, based on yours, without having to change the whole layout? So WITH using h3 and p tags?
Anybody 's got another solution please?
Ulricht, I gave it a try with your entire code, and gave CSS layout lines to the DIV1_title,… and DIV1_content,… corresponding to my h3 and p-tags…
It works fine in Firefox and also layout is correct but it doesn’t expand in IE. The headers (DIV_titles) appear in the right layout, but clicking on them gives no result… Fix for IE maybe?
Does anyone happen to know the reason for this?
Just encountered a new problem, not JS related or so, but maybe this is a quick fix, otherwise I’ll post a new thread!
When i make my screen smaller, on IE, my site looks like it should be on half the screen, just some scrolling needed to be done, on firefox I’m getting an oversized header, and my content with the table with photo and text in it, is floating somewhere in the topleftcorner…
I think it could have something to do with the position relative or so, to make the JS code to work?
Or what can it be?
in attachment you can find the code of one of the pages with also the CSS from it!
It works on IE, still can’t get the Firefox screen to work, in attachment three printscreens: how it should be full screen, the smaller screen and correct version of IE, and the wrong one from Firefox!
I’m having also a bit of problems with the previous code, working with the height in IE. My height shouldn’t be more the 450, because there is a photo (as on the printscreens) next to the text that needs to be collapsed/expanded. That photo is on each page 450px high.
I’m having quite some text, but if I put the expanded text into font-size 14px, I just got it to the height from the photo. However, the same amount of text cannot be displayed on IE, because apparently they show text a bit larger then Firefox.
Is there a line of code that I can put into the css that adapts the size of the content-tag when it reaches Internet Explorer?
OR MAYBE EVEN BETTER:
Is it possible to make the div that has too much text to get on 450px height, have the option to scroll? So that only the text that isn’t displayed because of the heightrestriction can be read through scrolling?
This indeed helps! However, the vertical scrolling is fine, BUT now, he places also a horizontal scroll bar, which is obviously not the intention. Plus, this has also the disadvantage that the height of the DIV1_title becomes higher because of the horizontal scroll bar.
So any suggestions to get rid of the horizontal? I put an prtscrn to show you.
Concerning the IE font problem, I use normally CSS, as I am not used on doing layout with js… So any tips on how to set the font-size through js? If I put the line for IE into js, does that mean I can delete the css-line. In other words would they interfere with eachother?
If I put the line for IE into js, does that mean I can delete the css-line.
if you did the styling with js you could remove that css…
In other words would they interfere with eachother?
i would imagine so yes, if the css yes one thing and the js says something else then i guess which ever runs last would have precedence over the other.