When a page loads, four characters are displayed, of which only one is displayed. There are two arrows. One on the left and one on the right. When you press the left arrow, the present character disappears, and the previous character disappears. When you press the right arrow, the present character disappears, and the next character disappears. I figured out how to fadeOut the current character on the screen, but I don’t know how to fadeIn the next or previous character when they click on the arrows.
Here is the fiddle I created to illustrate the problem: http://jsfiddle.net/9K7bf/32/
And here is the code:
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();
});
});
user3722439
source
share