name : script.js
// Load is used to ensure all images have been loaded, impossible with document

$(window).load(function () {

	var gutter = parseInt(jQuery('.post').css('marginBottom'));
	var container = jQuery('#posts');


	container.masonry({
		gutter: gutter,
		itemSelector: '.post',
		columnWidth: '.post'
	});
	jQuery(window).bind('resize', function () {

		if (!jQuery('#posts').parent().hasClass('container')) {
			post_width = jQuery('.post').width() + gutter;
			jQuery('#posts, body > #grid').css('width', 'auto');
			posts_per_row = jQuery('#posts').innerWidth() / post_width;
			floor_posts_width = (Math.floor(posts_per_row) * post_width) - gutter;
			ceil_posts_width = (Math.ceil(posts_per_row) * post_width) - gutter;
			posts_width = (ceil_posts_width > jQuery('#posts').innerWidth()) ? floor_posts_width : ceil_posts_width;
			if (posts_width == jQuery('.post').width()) {
				posts_width = '100%';
			}
			jQuery('#posts, #grid').css('width', posts_width);
			jQuery('#grid').css({'margin': '0 auto'});

		}
	}).trigger('resize');
	


});

© 2024 UnknownSec