Created
July 9, 2014 15:46
-
-
Save ayozebarrera/d3bd03edc523a2629771 to your computer and use it in GitHub Desktop.
Simple media gallery using transform translateX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
activeGallery: function(){ | |
var width = 466; /* ancho de cada elemento + separación */ | |
var positions = $('.slideGallery .media').length; /* 6 elements */ | |
var pos = 0; | |
$('.slideGallery .controller.right').click(function(){ | |
if (pos < positions){ // Limitar la galería | |
$('.slideGallery .controller.left').fadeIn('slow'); //mostramos el controlador opuesto | |
pos++; | |
if (pos >= positions-2){ //-2 is because the gallery is a 2elements/page.Will change in another design. | |
//this if is to set a maximum value and not set the value using pos (50 super clicks = pos 50). | |
var max = (positions-2)*width; | |
$('.slideGallery .controller.right').fadeOut('slow'); //max position so, hiding this controller! | |
$('.slideGallery .slideWrapper').css({ | |
'-webkit-transform':'translateX(-'+max+'px)', | |
'-moz-transform':'translateX(-'+max+'px)', | |
'-ms-transform':'translateX(-'+max+'px)', | |
'-o-transform':'translateX(-'+max+'px)', | |
'transform':'translateX(-'+max+'px)' | |
}); | |
} | |
else{ //if not the last or higher, keep translatingX :) | |
$('.slideGallery .slideWrapper').css({ | |
'-webkit-transform':'translateX(-'+pos*width+'px)', | |
'-moz-transform':'translateX(-'+pos*width+'px)', | |
'-ms-transform':'translateX(-'+pos*width+'px)', | |
'-o-transform':'translateX(-'+pos*width+'px)', | |
'transform':'translateX(-'+pos*width+'px)' | |
}); | |
} | |
} | |
}); | |
$('.slideGallery .controller.left').click(function(){ | |
if (pos > 0){ | |
$('.slideGallery .controller.right').fadeIn('slow'); | |
pos--; | |
if (pos == 0){ | |
$('.slideGallery .slideWrapper').css({ | |
'-webkit-transform':'translateX(0px)', | |
'-moz-transform':'translateX(0px)', | |
'-ms-transform':'translateX(0px)', | |
'-o-transform':'translateX(0px)', | |
'transform':'translateX(0px)' | |
}); | |
$('.slideGallery .controller.left').fadeOut('slow'); | |
} | |
else{ | |
$('.slideGallery .slideWrapper').css({ | |
'-webkit-transform':'translateX(-'+pos*width+'px)', | |
'-moz-transform':'translateX(-'+pos*width+'px)', | |
'-ms-transform':'translateX(-'+pos*width+'px)', | |
'-o-transform':'translateX(-'+pos*width+'px)', | |
'transform':'translateX(-'+pos*width+'px)' | |
}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment