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 trialGina Scalpone
21,330 PointsProblem with slideshow; unexpected refresh
Hi, I am designing a slideshow with jQuery (very simple, no timer or transitions, at least not yet). I'm stacking all the images on top of each other and revealing them by moving an id from image to image, which sets the z-index really high. The problem I'm finding is that every time I run it, my website unexpectedly refreshes, and the z-index goes back to the first image.
<div class="comic group">
<img id="top-image" src="img/page1.jpg">
<img src="img/page2.jpg">
<img src="img/page3.jpg">
<img src="img/page4.jpg">
</div>
#slideshow {
width: 700px;
height: 935px;
margin: 0 auto;
position: relative;
}
.slide {
width: 700px;
height: 935px;
position: absolute;
left: 0;
top: 0;
}
.comic {
width: 100%;
}
.comic img {
width: 50%;
float: left;
padding: 10px 2%;
}
.comic img {
width: 50%;
float: left;
padding: ;
}
.arrow {
z-index: 200;
position: absolute;
font-size: 3em;
background: rgba(255, 255, 255, .5);
padding: 0 15px 5px;
top: 10px;
border-radius: 5px;
}
#left {
left: 10px;
}
#right {
right: 10px;
}
#top-image {
z-index: 100;
}
}
$(".comic").attr('id', 'slideshow');
$("#slideshow").removeClass("comic");
$("#slideshow img").addClass("slide");
$("#slideshow").append('<p class="arrow" id="left"><a href=""><</a></p>');
$("#slideshow").append('<p class="arrow" id="right"><a href="">></a></p>');
$("#right").click(function() {
$currentImage = $("#top-image");
$currentImage.next().attr('id', 'top-image');
$currentImage.removeAttr('id', 'top-image');
});
1 Answer
David Clausen
11,403 PointsEven blank link like
<a href="">
is actually calling a new page ie refresh. So each time the arrow is clicked its refreshing your page. Prevent default behavior or change it to a button instead.