Reputation: 51
I am experimenting with an image fader rotater which I found on jsFiddle. I am having problems containing the images within a table, as the image always overlaps the table borders. Is there a way to ensure the table height is the same height as the images (my table is defined using percentages). Here is the code:
$('.fadein img:gt(0)').hide();
setInterval(function() {
$('.fadein :first-child').fadeOut()
.next('img')
.fadeIn()
.end()
.appendTo('.fadein');
}, 4000); // 4 seconds
.fader {
position: relative;
height: 100%;
width: 100%px;
}
.fadein {
position: relative;
height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table border="1" width=100% class="fader">
<tr>
<td width="70%">
<div class="fadein">
<img src="http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg">
<img src="http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg">
<img src="http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg">
<img src="http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg">
<img src="http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg">
</div>
</td>
<td>testing 123</td>
</tr>
</table>
Upvotes: 3
Views: 347
Reputation: 20935
I believe your issue may be coming from the fact that for a small amount of time, 2 of the images show up at the same time causing overlapping issues.
If you add some delay()
to your function then it should sort your issue out.
$('.fadein img:gt(0)').hide();
setInterval(function() {
$('.fadein :first-child').fadeOut('500').next().delay('400').fadeIn('500').end().appendTo('.fadein');
setTimeout(function() {
$('.fadein :first-child').css('display', 'block');
}, 400);
}, 4000);
.fader {
position: relative;
height: 100%;
width: 100%;
}
.fadein {
position: relative;
height: 100%;
}
.fadein img {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table border="1" width=100% class="fader">
<tr>
<td width="70%" class="fadein">
<img src="http://farm9.staticflickr.com/8359/8450229021_9d660578b4_n.jpg">
<img src="http://farm9.staticflickr.com/8510/8452880627_0e673b24d8_n.jpg">
<img src="http://farm9.staticflickr.com/8108/8456552856_a843b7a5e1_n.jpg">
<img src="http://farm9.staticflickr.com/8230/8457936603_f2c8f48691_n.jpg">
<img src="http://farm9.staticflickr.com/8329/8447290659_02c4765928_n.jpg">
</td>
<td>testing 123</td>
</tr>
</table>
Upvotes: 3