[英]display text when image on-click/hide text when different image click
I have created the following effects on the images seen here . 我对此处看到的图像产生了以下影响。 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. 太酷了,但是现在我需要文本1st:Sun来显示和隐藏其图形按钮。 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. 单词“ Sun”是需要链接到URL的链接,因此必须与图像效果代码分开。
What jQuery or javascript code do I need to do this? 我需要什么jQuery或javascript代码?
ps How do I properly post the code I have now. ps如何正确发布现在的代码。 I tried to paste code in "enter code here," but received errors 我尝试将代码粘贴到“在此处输入代码”中,但是收到错误
This is fairly simple if you add rel="img-id"
to each link you want to hide or show as follows: 如果将rel="img-id"
到要隐藏或显示的每个链接中,这将非常简单:
<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: 然后如下更新您的就绪函数jQuery:
// 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;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.