Well, The foundation of the script works correctly, before I add the timeout, which leaves me at a loss because it's not related at all the preceding statements. The timeout throws a wrench in the whole thing, and actually seems to not work at all even when it can read the variables. When the div sections do switch, they show instantly. This changes when I remove the "8*i" millisecond expression, and it will then display a single delay for the entire loop of whatever literal value I give, when it should give a delay each time it iterates(so far as i understand, which obviously is incorrect).
I'll explain what I was thinking when i started writing this.
The foundation loops through my array "ids", and compares each position with the parameter passed by the onclick event, if the comparison doesn't evaluate to true, it sets display to "none", if it does of course it sets display to "block".
Code:
<script type="text/javascript">
var ids=['features','cs','faq'];
function fire(id)
{
var myobj=document.getElementById(id).style;
for (var i=0;i<ids.length;i++)
{
if (ids[i]==id)
{
myobj.display='block';
}
else
{
document.getElementById(ids[i]).style.display='none';
}
}
}
</script>
<div><input type='submit' Onclick='fire("faq")' value='faq'><input type='submit' Onclick='fire("features")' value='feat'><input type='submit' Onclick='fire("cs")' value='cs'></div>
<div id="faq" style="display:none;">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<div id="cs" style="display:none;">
<p>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
</div>
<div id="features">
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
</p>
</div>
If you want to try it out, it should work fine. That took me all of two minutes to figure out and write, I thought the rest was that simple too(and dangit according to the way W3schools describes things it should be).
What I needed to do then was make it invisible when its display property was set to block, to facilitate a fade in without a blink side effect(opacity 100%-->0%-->100% is bad right?)
Then I needed to gradually increase the opacity from zero, and the only way I know to increment was with a loop, so of course I added a loop according to w3schools, but since the loop is instant as far as we're concerned, I added a timeout again according to its description at w3schools.
I had thought that the loop, according to the way W3schools defines things, would work like so:
----
1st iteration:
i=0
opacity set to (0/10)=0 and delay set to (8*0)=0 miliseconds.
2nd iteration:
i=1
opacity set to(1/10)=.1 delay set to (8*1)=8 milliseconds.
----
And so on! The only obvious error I noted was that to determine opacity "i" should be devided by 100 instead of 10, so that it evaluates to 1 on the final iteration, because the opacity property treats 1 as 100%. The total delay should have been just right as it's based off one I've seen.
I've looked at some other peoples cross faders, and they use a loop and a timeout as well! I just don't get what the difference is between what I've done, except that they always seem to join two strings together when defining the function that the delay is supposed to be applied to.
For example the cross fader that inspired my attempt uses:
Code:
setTimeout( 'setOpacity(' + (i / 10) + ')' , 8 * i );
where setOpacity is:
Code:
function setOpacity( value )
{
document.getElementById("styled_popup").style.opacity = value / 10;
}
It's completely maddening! And that's before I try to figure out why the timeout that can read the variables completely fudges the scripts ability to set display to none when the initial comparison evaluates to false! The timeout should change nothing regarding that! It's never run if it evaluates to false! ... AHHH!!
EDIT:
I searched for the original page where I first encountered the fade-in effect. You can view it here.
That fade effect is I'm trying to achieve whenever I switch a div.
Bookmarks