【发布时间】:2014-07-14 12:31:10
【问题描述】:
页面加载时,共有四个字符,其中仅显示一个。 有两个箭头。一个在左边,一个在右边。 单击左箭头时,当前字符淡出,前一个字符淡入。单击右箭头时,当前字符淡出,下一个字符淡入。 我已经弄清楚如何淡出屏幕中的当前字符,但不知道如何在单击箭头时淡入下一个或上一个字符。
这是我为说明问题而创建的小提琴:http://jsfiddle.net/9K7bf/32/
这里是代码:
HTML:
<section id="characters">
<div id="one" class="character"></div>
<div id="two" class="character"></div>
<div id="three" class="character"></div>
<div id="four" class="character"></div>
</section>
<div id="arrow-left"></div>
<div id="arrow-right"></div>
CSS:
#characters{
width: 100%;
height: 100px;
}
#one{
height: 50px;
width: 50px;
display: block;
background-color: green;
margin: 100px auto;
}
#two{
height: 50px;
width: 50px;
display: none;
background-color: blue;
margin: 100px auto;
}
#three{
height: 50px;
width: 50px;
display: none;
background-color: purple;
margin: 100px auto;
}
#four{
height: 50px;
width: 50px;
display: none;
background-color: black;
margin: 100px auto;
}
#arrow-left{
height: 25px;
width: 25px;
display: block;
background-color: black;
float: left;
}
#arrow-right{
height: 25px;
width: 25px;
display: block;
background-color: black;
float: right;
}
jQuery:
$(document).ready(function(){
$("#arrow-right").on('click', function(){
$(".character").fadeOut().this();
});
$("#arrow-left").on('click', function(){
$(".character").fadeOut().this();
});
});
【问题讨论】:
-
+1 表示小提琴和一般的学习意愿
-
您在寻找类似this 的东西吗?如果是,我将在答案中解释做了什么。并且出于同样的原因 +1,原因与 amenthes 所说的相同。
-
非常感谢。我不想把我的问题扔在那里以获得快速答案。该平台旨在记录问题和答案,以便其他人也可以从中学习。我这是我的归因方式:)
标签: javascript jquery html css