Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. $.fn.colNav = (function ($) {
  2. var getNmrCols = function (el) {
  3. var $cols = $(el),
  4. width = getWidth($cols),
  5. colWidth = getColWidth($cols);
  6. return Math.ceil(width / colWidth);
  7. },
  8. getWidth = function (el) {
  9. var $cols = $(el),
  10. $clone = $cols.clone(true),
  11. width = $clone
  12. .css({
  13. left: '-9999px',
  14. top: '-9999px',
  15. position: 'absolute'
  16. })
  17. .appendTo('body')
  18. .width();
  19. $clone.remove();
  20. return width;
  21. },
  22. getColWidth = function (el) {
  23. var $cols = $(el);
  24. return $cols.width() + parseInt($cols.css('-webkit-column-gap'));
  25. };
  26. return function (specs) {
  27. $(this).each(function () {
  28. var $cols = $(this),
  29. $nav = $(specs.nav),
  30. colWidth = getColWidth($cols),
  31. nmrCols = getNmrCols($cols),
  32. i;
  33. for (i = 0; i < nmrCols; i += 1) {
  34. var $li = $('<li />'),
  35. $a = $('<a />').attr('href', 'javascript:;').text(i + 1);
  36. $li.append($a).appendTo($nav);
  37. $a.click(function (i) {
  38. return function () {
  39. $cols.animate({
  40. left: -colWidth * i + 'px'
  41. }, 250);
  42. };
  43. }(i));
  44. }
  45. });
  46. };
  47. }(jQuery));
Add Comment
Please, Sign In to add comment