The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Hiding/Showing a Div with JavaScript.
What action do I need to use to hide or show a div, and everything it contains. I know that it needs a seperate ID, and how to call the function, but I need to know the action.
My current way of going about this(without the action of course). Code:
<script type="text/javascript"> hcur=0 function hidelast(){ switch(hcur){ case 0: hide div0 break case 1: hide div1 break} } function header_main(){ if ( hcur!=0 ){ hidelast() hcur = 0 show div0} } function header_diff1(){ if ( hcur!=1 ){ hidelast() hcur = 1 show div1} } </script> ... <div id="div0"> <a href="url"><img onmouseover="header_main()"></a> </div> <div id="div1"> <a href="url"><img onmouseover="header_diff1()"></a> </div> |
#2
|
||||
|
||||
For you div code, you need to add the display style like "<div id=xxx style="display: none;">"
|
#3
|
|||
|
|||
So I would use...
Code:
document.getElementById('div1').style.display="none" Code:
document.getElementById('div1').style.display="inline" EDIT: This works for the hiding, but not for the showing. I tried visibility, same thing. |
#4
|
||||
|
||||
This is the javascript I use:
PHP Code:
PHP Code:
|
#5
|
||||
|
||||
To hide, set display to "none" and to show, set display to "" (an empty string.)
|
#6
|
|||
|
|||
Thank you, I made this function modeled after that. However it's not working, is my syntax wrong?
hcur stores the id of the current element shown. hx tells how many additional elements are included. (if theres more than one) hcur + 'b' is the button, it changes images. hcur + '2', and hcur + '3' are additional elements that should be hidden/shown if needed. Code:
function switchheader(id, x) { if ( hcur != id ){ document.getElementById(hcur).style.display = 'none'; document.getElementById(hcur + 'b').src = '/styles/7M-v1/new/' + hcur + '.png'; if (hx != 1){ document.getElementById(hcur + '2').style.display = 'none'; if (hx == 3){ document.getElementById(hcur + '3').style.display = 'none';} } hcur = document.getElementById(id); document.getElementById(hcur).style.display = 'block'; document.getElementById(hcur + 'b').src = '/styles/7M-v1/new/' + hcur + '_alt.png'; if (x != 1){ document.getElementById(hcur + '2').style.display = 'block'; if (hx == 3){ document.getElementById(hcur + '3').style.display = 'block';} } hx = x; } } Code:
<img onMouseover="switcheader('main', 2)" src="/styles/7M-v1/new/main.png" /> <img onMouseover="switcheader('projects', 1)" src="/styles/7M-v1/new/projects.png" /><td> PS: Saw your message just now analog i'll make that change, however this code above isn't working at all. |
#7
|
||||
|
||||
To begin with, hcur isn't defined in the function. I didn't get any further than that. But why make it that complicated? Put your two alternate headers within a div for each one, and then do something like this. Your two divs have id's headerone and headertwo.
Code:
function toggle_header() { var el = document.getElementById('headerone'); if (el.style.display == 'none') { el.style.display = ''; document.getElementById('headertwo').style.display = 'none'; } else { el.style.display = 'none'; document.getElementById('headertwo').style.display = ''; } } |
#8
|
|||
|
|||
That wouldn't work. I'm switching between about 6 divs, and it seems wasteful to check the state of each div when I can just use a variable.
I simplified it, sorry, kinda used to going overboard when coding (other language). Really don't like to use specifics. Code:
var hcur='logo'; function switchheader(id){ if ( hcur != id ){ document.getElementById(hcur).style.display = 'none'; document.getElementById(hcur + 'b').src = '/styles/7M-v1/new/hb_' + hcur + '.png'; document.getElementById(id).style.display = ''; document.getElementById(id + 'b').src = '/styles/7M-v1/new/hb_' + hcur + '_alt.png'; if (hcur == 'logo'){ document.getElementById('logo2').style.display = 'none';} if (id == 'logo'){ document.getElementById('logo2').style.display = '';} hcur = id; } }
If the new id is not equal to the current id (why switch to the same?), then continue with the switch, else do nothing. Hide the current div, and switch the current button back to default. Then show the new div, and switch the new button to alternate. If the past id was logo, hide the extra div. If the new id is logo, show the extra div. Set hcur to the new id as it is now the current, and end function. |
#9
|
||||
|
||||
After a quick glance, it looks good. Try putting an alert('x'); after each line to identify where it chokes.
|
#10
|
|||
|
|||
Ok, I did that. My code exactly for that...
Code:
var hcur='logo'; function switchheader(id){ alert('runs! id:' + id + ' hcur:' + hcur); if ( hcur != id ){ alert('1'); document.getElementById(hcur).style.display = 'none'; alert('2'); document.getElementById(hcur + 'b').src = '/styles/7M-v1/new/hb_' + hcur + '.png'; alert('3'); document.getElementById(id).style.display = ''; alert('4'); document.getElementById(id + 'b').src = '/styles/7M-v1/new/hb_' + hcur + '_alt.png'; alert('5'); if (hcur == 'logo'){ alert('6'); document.getElementById('logo2').style.display = 'none';} alert('7'); if (id == 'logo'){ alert('8'); document.getElementById('logo2').style.display = '';} alert('9'); hcur = id; alert('10'); } } Code:
document.getElementById(hcur + 'b').src = '/styles/7M-v1/new/hb_' + hcur + '.png'; PS: THe problem defiantly lies in those 2 lines, I commented them out and it works. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|