我有这段代码可以淡出并在单击相关链接时更改 div。我希望图像作为我的链接,而不仅仅是“经销商、广告等”。除此之外,虽然我会在相应的 div 处于活动状态时将图像更改为另一个图像。
举个例子。单击“dealeroff.jpg”图像时,它将变为“dealeron.jpg”,直到单击另一个图像并更改活动div。
<ul id="controlls">
<li><a href="#" id="one" class="dealer">Dealer</a></li>
<li><a href="#" id="two" class="advertise">Advertise</a></li>
<li><a href="#" id="three" class="social">Social Media</a></li>
<li><a href="#" id="four" class="need">Need</a></li>
</ul>
<div id="slider">
<div id="dealer">
<p>If you click on this paragraph
you'll see it just fade away.
</p>
</div>
<div id="advertise">
<p>If you click on this paragraph
you'll see it just fade away.
</p>
</div>
<div id="social">
<p>If you click on this paragraph
you'll see it just fade away.
</p>
</div>
<div id="need">
<p>If you click on this paragraph
you'll see it just fade away.
</p>
</div>
</div>
$("#controlls li a").click(function(e) {
e.preventDefault();
var id = $(this).attr('class'); // get class of clicked anchor tag
// first fadeOut the visible div
$('#slider div:visible').fadeOut(500, function() {
// after fadeOut complete show target div
$('div#' + id).fadeIn();
})
});
任何帮助都会很棒:)