Guest User

Untitled

a guest
Jan 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(function() {
  3. function getCols(containerWidth, itemWidth) {
  4. var cols = Math.floor(containerWidth / itemWidth);
  5. return cols;
  6. }
  7.  
  8. function getPageCols() {
  9. var containerWidth = $('.content').width();
  10. var itemWidth = $('.tile').width() + parseInt($('.tile').css('margin-right'));
  11.  
  12. return getCols(containerWidth, itemWidth);
  13. }
  14.  
  15. function moveTile($tile, col, cols) {
  16. var width = $tile.width();
  17.  
  18. var prevTileSelector = '.col' + col;
  19. var $prevTile = $tile.prevAll(prevTileSelector);
  20.  
  21. var top =
  22. $prevTile.size() > 0 ?
  23. $prevTile.offset().top + $prevTile.height() :
  24. 0;
  25.  
  26. var left = (width * col) - width;
  27.  
  28. $tile.css({
  29. 'top': top,
  30. 'left': left
  31. });
  32. }
  33.  
  34. function onLoadOrResize(event, cols) {
  35. var $tile = $(this);
  36. var col = (Number($tile.attr('rel')) % cols) || cols;
  37.  
  38. $tile.attr('class', 'tile col' + col);
  39. moveTile($tile, col, cols);
  40. }
  41.  
  42. $(window).resize(function() {
  43. var cols = getPageCols();
  44. $('.tile').trigger('loadorresize', [cols]);
  45. });
  46.  
  47. $('.tile').live('loadorresize', onLoadOrResize);
  48.  
  49. $(window).resize();
  50. });
  51. </script>
Add Comment
Please, Sign In to add comment