Javascript 单击相应的定位点时,淡入div代替另一个div
我有3个div,2个设置为显示none,1个可见 下面我有3个链接,每个链接对应一个div,当单击其中一个链接时,我需要它在相关div中淡出,并淡出当前活动的div(如果有意义的话) 我添加了一个提琴,正如你看到的“董事”正在显示的那样,我希望能够单击底部的一个链接,例如accounts,然后让它淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡出淡入淡出淡出淡入淡出淡出淡出淡出淡出淡出淡出Javascript 单击相应的定位点时,淡入div代替另一个div,javascript,jquery,Javascript,Jquery,我有3个div,2个设置为显示none,1个可见 下面我有3个链接,每个链接对应一个div,当单击其中一个链接时,我需要它在相关div中淡出,并淡出当前活动的div(如果有意义的话) 我添加了一个提琴,正如你看到的“董事”正在显示的那样,我希望能够单击底部的一个链接,例如accounts,然后让它淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡入淡出淡出淡入淡出淡出淡入淡出淡出淡出淡出淡出淡出淡出 如果您将类更改为包含div和触发链接上的title attr,并
如果您将类更改为包含div和触发链接上的title attr,并向其添加“fader”类(如下示例): 然后,脚本可以如下所示:
$(document).ready(function(){
// On link click, the corresponding div needs to fade into the team-profile and the other
// needs to fade out...
$('div.fader[title="directors"]').show();
$('a.fader').click(function (e) {
var t = $(this).attr('title');
$('div.fader').hide('slow');
$('div.fader[title="' + t + '"]').show('slow');
e.preventDefault();
return false;
});
});
在JSFIDLE上运行并测试。
完整的HTML源代码如下:
<div class="fader" title="directors">
<h2>Our Directors</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div class="fader" title="sales">
<h2>Our Sales Team</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div class="fader" title="accounts">
<h2>Our Accounts Team</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div>
<br /><br />
<a href="#" class="fader" title="accounts">Accounts</a><br />
<a href="#" class="fader" title="sales">sales</a><br />
<a href="#" class="fader" title="directors">directors</a>
我们的董事
-
-
-
我们的销售团队
-
-
我们的客户团队
-
-
希望这有帮助。
皮特
$(document).ready(function(){
// On link click, the corresponding div needs to fade into the team-profile and the other
// needs to fade out...
$('div.fader[title="directors"]').show();
$('a.fader').click(function (e) {
var t = $(this).attr('title');
$('div.fader').hide('slow');
$('div.fader[title="' + t + '"]').show('slow');
e.preventDefault();
return false;
});
});
<div class="fader" title="directors">
<h2>Our Directors</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div class="fader" title="sales">
<h2>Our Sales Team</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div class="fader" title="accounts">
<h2>Our Accounts Team</h2>
<ul class="team">
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
<li>
<a href="#">
<img src="http://www.placehold.it/218x108" class="fl"/>
<div class="information">
<p class="block-left">
<span class="name-title">Name</span>
<span class="name">Thomas O'Donoghue</span>
<span class="job-title">Job Title</span>
<span class="job">Managing Director</span>
</p>
<p class="block-right">
<span class="biography-title">Biography</span>
Thomas is the Managing Director of Website FX, and ha...
</p>
</div>
</a>
</li>
</ul>
</div>
<div>
<br /><br />
<a href="#" class="fader" title="accounts">Accounts</a><br />
<a href="#" class="fader" title="sales">sales</a><br />
<a href="#" class="fader" title="directors">directors</a>