Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(function() {
- function getCols(containerWidth, itemWidth) {
- var cols = Math.floor(containerWidth / itemWidth);
- return cols;
- }
- function getPageCols() {
- var containerWidth = $('.content').width();
- var itemWidth = $('.tile').width() + parseInt($('.tile').css('margin-right'));
- return getCols(containerWidth, itemWidth);
- }
- function moveTile($tile, col, cols) {
- var width = $tile.width();
- var prevTileSelector = '.col' + col;
- var $prevTile = $tile.prevAll(prevTileSelector);
- var top =
- $prevTile.size() > 0 ?
- $prevTile.offset().top + $prevTile.height() :
- 0;
- var left = (width * col) - width;
- $tile.css({
- 'top': top,
- 'left': left
- });
- }
- function onLoadOrResize(event, cols) {
- var $tile = $(this);
- var col = (Number($tile.attr('rel')) % cols) || cols;
- $tile.attr('class', 'tile col' + col);
- moveTile($tile, col, cols);
- }
- $(window).resize(function() {
- var cols = getPageCols();
- $('.tile').trigger('loadorresize', [cols]);
- });
- $('.tile').live('loadorresize', onLoadOrResize);
- $(window).resize();
- });
- </script>
Add Comment
Please, Sign In to add comment