Reputation: 21
I'm using Galleria image gallery on my website. The problem is: When I run galleria first time, and the initial image is not first, Galleria shows the initial for a moment and then slides back to the first image. When i click on thumbs more, Galleria acts correctly, so this happens only first time. Here is the code I use to initialise galleria:
$('.thumbnail').live('click', function(){ var image_number = getNumber($(this).attr('id')); Galleria.ready(function(options) { this.show(image_number); }); Galleria.run('#galleria'); $('#galleria_frame').show(); });
getNumber is my function that returns the number of image in gallery, first image has number 0, second - number 1 etc.
where is my mistake? Why does galleria slide back to first image when I click on the .thumbnail the first time?
Upvotes: 2
Views: 809
Reputation: 108500
There are a couple of problems with your code.
1) you are initializing Galleria multiple times (every time you click a thumbnail)
2) you are adding multiple listeners to the ready
event, each time you tell galleria to show different images onload.
Try this instead:
$('.thumbnail').live('click', function(){
var image_number = getNumber($(this).attr('id')),
instance = $('#galleria').data('galleria');
// if Galleria already loaded, just show the index:
if (instance) {
instance.show(image_number);
} else {
// else fire up Galleria and pass the index as an option
$('#galleria_frame').show();
Galleria.run('#galleria', { show: image_number });
}
});
Upvotes: 2