views:

58

answers:

1

Hi

I have created the following effects on the images seen here http://techavid.com/design/test3.html . You see when you hover and then click on each image, they go from grey to color. When you click on one - the others go grey and the one clicked remains color. That's cool, but now I need the text 1st: Sun for example to display and hide along with its graphic button. The word "Sun," is a link that needs to link out to a URL so it has to be separated from the image effect code.

What jquery or javascript code do I need to do this?

thanks, jonah

p.s. How do i properly post the code I have now. I tried to paste code in "enter code here," but received errors - thnx

+1  A: 

This is fairly simple if you add rel="img-id" to each link you want to hide or show as follows:

<div id="wrapper"> 

<div id="navigation"> 
  <a id="sun" href="#">sunimg</a> 
  <a id="plane" href="#">planeimg</a> 
  <a id="nano" href="#">nanoimg</a> 
</div> 
<div style="clear:both"></div> 

<div id="popuptext">1st: <a href="#" rel="sun">Sun</a> 
2nd: <a href="#" rel="plane">Airplane</a> 
3rd: <a href="#" rel="nano">Nano</a> 
</div> 

</div> 

And then update your ready function jQuery as follows:

  // target each link in the navigation div
  $('#navigation a').click(function(e) {
    // link that you clicked
    clicked = $(this).attr('id');

    // this is faster than the .each() you used
    $('#navigation a').removeClass('active');
    $(this).addClass('active');

    // hide all links, then show the one with the same rel as the id clicked
    $('#popuptext a').hide();
    $('#popuptext a[rel='+clicked+']').show();

    // prevent the default link action
    return false;
  });
​
mVChr
Hi mVChr thank you very much. Do I need to add <img src="sun.png"> in between the href code <a id="sun" href="#"> </a> ?thanks again
Jonah1289
I just pulled the code directly from your test page, so what you wrap the a tag with is up to you. The important part is to have the ids in #navigation match the rels in #popuptext
mVChr
Woot - mVChr thanks again Im getting closer to what I've been trying to accomplish since yesterday :) JUst now the text options when clicked all appear under the sun. They need to appear under their own icons. Any suggestion ?
Jonah1289
hmm going to try and use absolute positioning for each. That might do the trick :)
Jonah1289
Awesome that about did it ... except on page load each image shows it's text. What to add so on page load only the active image (sun) and it's text "1st: Sun," show?
Jonah1289
You can read up on [display properties and other helpful HTML/CSS/JS for beginners here](http://www.tizag.com/cssT/display.php).
mVChr
thanks for your help, mVCHr!
Jonah1289