hope you are all doing well.
So I have gallery that is not using any plugin
$(document).ready(function() {
var index =1;
var images = ['1.jpg','2.jpg','3.jpg'];
var caption_text = ["title1","title2","title3"];
function rotateImage()
{
$('#gallery').fadeOut('fast', function()
{
$(this).attr('src','<?php echo base_url()."assets/highlight/";?>'+ images[index]);
$('span').text(caption_text[index]);
$(this).fadeIn('fast', function()
{
if (index == images.length-1)
{
index = 0;
}
else
{
index++;
}
});
});
}
setInterval (rotateImage, 2500);
$('.thumb').on('click', function() {
var img = $('<img />', {src : this.src,
'class': 'highlight_img'
});
var imageTitle = $(this).attr("title");
$('.highlight').html(img).show();
$('.highlight').append("<br/><span class='highlight_caption'>"+imageTitle+"</span>");
setInterval (rotateImage, 5000);
});
});
and this is my html
<div class='col-md-12 highlight'>
<img id='gallery' src='<?php echo site_url('assets/highlight/1.jpg');?>' height='300' class='highlight_img'/><br/>
<span id='highlight_caption' class='highlight_caption'>title1</span>
</div>
<div class='list'>
<div><img class='thumb' src='<?php echo site_url('assets/highlight/1.jpg');?>' height='75' title='title1'/></div>
<div><img class='thumb' src='<?php echo site_url('assets/highlight/2.jpg');?>' height='75' title='title2'/></div>
<div><img class='thumb' src='<?php echo site_url('assets/highlight/3.jpg');?>' height='75' title='title3'/></div>
Now, I can do the image rotation when the page load with no problem. Also, when i click the image thumbnail, the #gallery div will also change image based on the thumbnail I click
But, when I invoke the thumbnail on click function, the rotateImage() does not work anymore, I need to refresh the page to get the image rotating again.
How should I code to perform this?
Thank you!
EDIT:
Sorry for not being clear My question is, I have put "setInterval (rotateImage, 5000);" inside .thumb on click() function, I know it's running because I tried to console.log, and the script does execute, BUT why the image isn't changing?