我刚开始使用javascript,现在遇到了一些麻烦。我试图创建一个脚本,当一个小图片被点击,一个div幻灯片打开,并给出在图片中的人的个人信息。一行中有5幅图片,文本div位于每一行的底部。
如果再次单击相同的图像或下一行上的图像,则确保div被关闭,但如果在同一行上单击另一个图像,则保持打开状态并切换到没有动画的下一个描述。
环顾四周后,我想到了这个。
JS。
<script>
$(function () {
var tabContainers = $('div.tabs > div');
$('div.tabs ul.tabNavigation a').click(function () {
tabContainers.hide().filter(this.hash).slideToggle("slow");
tabContainers.hide().filter(this.hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
</script>
CSS。
<style type="text/css">
UL.tabNavigation {
list-style: none;
margin: 0;
padding: 0;
}
UL.tabNavigation LI {
display: inline;
}
UL.tabNavigation LI A {
border-left: 35px solid transparent;
border-right: 35px solid transparent;
}
A.selected {
border-left: 35px solid transparent;
border-right: 35px solid transparent;
border-bottom: 35px solid gray;
}
UL.tabNavigation LI A:focus {
outline: 0;
}
div.tabs > div {
padding: 5px;
margin-top: 3px;
border: 0 px solid #333;
}
div.tabs > div h2 {
margin-top: 0;
}
HTML。
<div class="container">
<div class="tabs">
<ul class="tabNavigation">
<li><a href="#alex"><img id="flip" src="{% static 'img/alex-headshot-stone.png' %}" alt="Photo of Alex Chamberlain" class="img-team img-thumbnail"/></a></li>
<li><a href="#ed"><img id="flip" src="{% static 'img/ed_snajder.jpg' %}" alt="Photo of Ed Snajder" class="img-team img-thumbnail"/></a></li>
<li><a href="#nicole"><img id="flip" src="{% static 'img/nicole-phelps.jpg' %}" alt="Photo of Nicole Phelps" class="img-team img-thumbnail"/></a></li>
</ul>
<div id="alex">
<h3>Alex Chamberlain<span id=":14h" tabindex="-1"></span></h3>
<p><b>Puppet Labs</b><br>
Software Quality Assurance Engineer</p>
<ul>
<li>Linked-in: <a href="http://www.linkedin.com/pub/alex-chamberlain/35/9a/911">Alex Chamberlain</a></li>
</ul>
<br />
<p>Alex Chamberlain has been involved in the process of software development in various capacities for almost twenty years, with a special interest in solving real-world problems by applying a thoughtful, user-centered approach to software design. He has worked as a software engineer, business systems analyst, software tester, and college teacher of computer programming. In his current position at Puppet Labs he is involved in all phases of testing Puppet Enterprise, an automated system-administration and configuration management tool, from high-level product-requirements analysis through hands-on manual testing.</p>
<p> Currently he is focused on development of automated web application testing tools. When not staring at a screen, he enjoys playing the guitar loudly and badly, cooking, taking care of his two elderly cats, and tinkering with vintage Japanese motorcycles.</p>
</div>
<div id="ed">
<h3>Ed Snajder<span id=":14h2" tabindex="-1"></span></h3>
<p><b>Jive Software</b><br>
Staff DB Engineer</p>
<ul>
<li>Linked-in: <a href="http://www.linkedin.com/in/edinor">Ed Snajder</a></li>
<li>O'Reilly Webcasts: <a href="http://www.oreilly.com/pub/au/5704">Ed Snajder</a></li>
</ul>
<p>Ed is the Database Administrator at Jive Software. He has been administering databases and analyzing data and for over 10 years, and today finds himself working with PostgreSQL, MySQL, SQL Server and Oracle relational database engines, as well as HBase, Pig and other distributed technologies. He works on query and data structure design, performance optimization, systems configuration and troubleshooting for both internal and on-premises systems. </p>
<p>When not having fun with databases, Ed is an aspiring hacker, with a self-built 3D printer, a couple of Raspberry Pis, and several mostly finished Arduino projects. An avid Portland tech community supporter, Ed has spoken at and participated in the PostgreSQL User Group, OSCON, Portland Code Camp, SQL Saturday and the Oregon SQL Developers' Group.</p>
</div>
<div id="nicole">
<h3>Nicole Phelps<span id=":14h3" tabindex="-1"></span></h3>
<p><b>Mash LLC</b><br>
Software Developer</p>
<ul>
<li>Linked-in: <a href="https://www.linkedin.com/pub/nicole-phelps/46/79a/927">Nicole Phelps</a></li>
</ul>
<br />
<p>Nicole is a software developer at Mash LLC in Portland, working on a project for Google. She wrote her first program as a sophomore at Oregon State University and, ever since, has become immersed in software development and entrepreneurship. While currently finishing her OSU degree in Computer Science with a focus on HCI, Nicole is starting the OSU App Challenge, a competition aimed at helping other students develop their technical skills and creativity. </p>
<p>She has done mobile application development for OSU, Maps Credit Union, BuyBott, and Bioniq Health. Some development tools she enjoys using the most are Native iOS, Ruby on Rails, and Titanium development. When not on the computer, Nicole is usually playing volleyball or reading sci-fi/fantasy books.</p>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-4" style="float:left"> <img src="{% static 'img/kelly.jpg' %}" alt="Photo of Kelly White" class="img-team img-thumbnail"/>
<h3>Kelly White<span id=":14h" tabindex="-1"></span></h3>
<p><b>Silvertail Software</b><br>
President</p>
<ul>
<li>Building Apps for Windows Phone: <a href="http://www.winphonedev.me/">Kelly White</a></li>
<li>Linked-in: <a href="https://www.linkedin.com/in/kellywhite">Kelly White</a></li>
</ul>
<br />
<p>Kelly White is the President of Silvertail Software, a software consultancy specializing in XAML solutions for the Windows Phone and Windows 8 App Stores. He has over 13 years of industry experience building web applications, and has a passion for startups as a serial entrepreneur. Kelly has served on the organizing boards for the Portland Code Camp, Portland Startup Weekend, and the Oregon Game Project Challenge. He also founded and previously ran the Silverlight and Windows Phone user groups in Portland, Oregon.</p>
<p> Kelly is a Microsoft MVP in Windows Phone Development, and speaks regularly at user groups, code camps, and other developer-related events throughout the Pacific Northwest on Windows Phone and Windows 8 App Development.</p>
</div>
</div>
</div>
这将匹配图像的正确文本,并给我动画,但我不知道如何开始时,隐藏的文本div,而不是动画时,单击下一个图像,或隐藏时,该图像再次点击。
如果有人能给我指明正确的方向,我会非常感激的。
发布于 2014-04-12 02:10:16
由于所有的图像都丢失了,而且所有的东西都在其他东西上,所以我从零开始,按照您的说明:
Fiddle
我将2行的5幅图像放在中进行测试:
每个图像行都有类.people
。
每个图像都有类.person
每个bio行都有一个类.bios
每个bio都有.bio
类
代码注释得很好:
$(‘.person’).click(函数(){) //获取一些信息var openRow = ( $('.bios:visible ').index() - 1) / 2;// openRow# var openImage =$(‘.bios:visible .bio:visible').index();// openImage# var currentRow = $(this).parent().index() / 2;// Clicked # var currentImage =$(.bios:visible.bio:visible).index();//单击图像# //隐藏所有单个bios $('.bio').hide();//仅显示选定的bio //隐藏所有生物集$('.bios').not(':eq(‘+ currentRow + ')').slideUp();//仅显示选定的bios集$('.bios').eq( currentRow ).slideDown();//如果单击了相同的图像,则为If (openRow == currentRow& openImage == currentImage) $('.bios').eq(currentRow).slideUp();//然后隐藏该集合。 });
希望这能有所帮助!
发布于 2014-04-12 01:06:22
我修改了你的JS这样就行了。注释是内联的。
$(function () {
var tabContainers = $('div.tabs > div');
$('div.tabs ul.tabNavigation a').click(function () {
if ($(this).hasClass('selected')) { // this checks if this is selected, and hide section if it was already selected tabContainers.hide();
$(this).removeClass('selected');
}
else { // this is when it is not selected
if (tabContainers.is(":visible")) { // if it is visible already, hide others and show current section without animation
tabContainers.hide().filter(this.hash).show();
}
else {
// it is not visible already, do your cool animation
tabContainers.hide().filter(this.hash).slideToggle("slow");
tabContainers.hide().filter(this.hash).show();
}
$('div.tabs ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
}
return false;
}); //.filter(':first').click(); // don't click the first one on load
// hide tab containers on load
tabContainers.hide();
});
我还把它发布在JS Fiddle http://jsfiddle.net/8VBfW/上
https://stackoverflow.com/questions/23024449
复制相似问题