Skip to content

Instantly share code, notes, and snippets.

@cj
Created October 29, 2014 23:42
Show Gist options
  • Save cj/5733a6fe3005d40c6955 to your computer and use it in GitHub Desktop.
Save cj/5733a6fe3005d40c6955 to your computer and use it in GitHub Desktop.
$('.thumbs').each(function () {
$('a', this).each(function () {
var $a = $(this);
// set ids, will use them later
$a.attr({id: $a.attr('href').replace(/[\/\.-]/g, '')});
});
var $thumbs = $(this),
$fotorama = $thumbs.clone();
$fotorama
.on('fotorama:show', function (e, fotorama) {
// pick the active thumb by id
$('#' + fotorama.activeFrame.id)
.addClass('active')
.siblings()
.removeClass('active');
})
.addClass('fotorama')
.removeClass('thumbs')
.insertBefore(this)
.fotorama({nav: false, width: '100%', maxHeight: 400, ratio: 3/2});
// get access to the API
var fotorama = $fotorama.data('fotorama');
$thumbs.on('click', 'a', function (e) {
e.preventDefault();
// show frame by id
fotorama.show(this.id);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment