Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ganta Hemanth
6,460 PointsThe Jquery code of the carousel is not working properly
The carousel works fine for 5 to 10 min. But after that time the images in the carousel start to display twice instead once.
The Html code is
<div id="carousel">
<div id="wrap">
<div class="active-slide fir"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
The CSS code is
/*Carousel */
#carousel
{
width:102%;
height:40em;
overflow:hidden;
display:none;
}
#wrap
{
width:700%;
height:40em;
}
#wrap div
{
width:14.4%;
height:40em;
float:left;
background-size:100% 100%;
}
#wrap>div:first-child
{
background-image:url('../images/11.jpg');
}
#wrap>div:nth-child(2)
{
background-image:url('../images/12.jpg');
}
#wrap>div:nth-child(3)
{
background-image:url('../images/13.jpg');
}
#wrap>div:nth-child(4)
{
background-image:url('../images/14.jpg');
}
#wrap>div:nth-child(5)
{
background-image:url('../images/16.png');
}
#wrap>div:last-child
{
background-image:url('../images/17.jpg');
}
The Jquery code is
var main = function(){
$('#menu>a').click(function(){
$('#menu ul').slideToggle('slow');
});
var currentslide,nextslide,count;
count = 0;
setInterval(function(){
count = count+1;
currentslide = $('.active-slide');
nextslide = currentslide.next();
if(count === 6)
{
nextslide = $('.fir');
count = 0;
}
currentslide.fadeOut(1000,function(){
nextslide.fadeIn(3500);
});
currentslide.removeClass('active-slide')
nextslide.fadeOut(1000).addClass('active-slide');
},4500);
$('p span:nth-child(2)').click(function(){
$('p span').toggle();
});
$('span span').click(function(){
$('p span').toggle();
});
};
$(document).ready(main);