Skip to content

Instantly share code, notes, and snippets.

@thotbox
Last active August 29, 2015 14:20
Show Gist options
  • Save thotbox/e5b8eb3604c7ddc71ca9 to your computer and use it in GitHub Desktop.
Save thotbox/e5b8eb3604c7ddc71ca9 to your computer and use it in GitHub Desktop.
JavaScript: Grid Images
// Grid Images
$(document).ready(function() {
if($('.grid_images').length && $('.grid_image').length) {
$('.grid_image').each(function() {
var gridID = $(this).attr('id');
gridID = gridID.replace('grid_image_', '');
var gridImage = $('#grid_source_' + gridID).attr('data-src');
var gridFloat = $('#grid_source_' + gridID).attr('data-float');
var gridWidth = $('#grid_source_' + gridID).attr('data-width');
$(this).html('<img src="' + gridImage + '">');
if (gridFloat === 'left') {
$(this).addClass('grid_image_left');
} else if (gridFloat === 'right') {
$(this).addClass('grid_image_right');
}
if (gridWidth === 'half') {
$(this).addClass('grid_image_half');
} else {
$(this).addClass('grid_image_full');
}
$('#grid_source_' + gridID).remove();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment