Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.fn.colNav = (function ($) {
- var getNmrCols = function (el) {
- var $cols = $(el),
- width = getWidth($cols),
- colWidth = getColWidth($cols);
- return Math.ceil(width / colWidth);
- },
- getWidth = function (el) {
- var $cols = $(el),
- $clone = $cols.clone(true),
- width = $clone
- .css({
- left: '-9999px',
- top: '-9999px',
- position: 'absolute'
- })
- .appendTo('body')
- .width();
- $clone.remove();
- return width;
- },
- getColWidth = function (el) {
- var $cols = $(el);
- return $cols.width() + parseInt($cols.css('-webkit-column-gap'));
- };
- return function (specs) {
- $(this).each(function () {
- var $cols = $(this),
- $nav = $(specs.nav),
- colWidth = getColWidth($cols),
- nmrCols = getNmrCols($cols),
- i;
- for (i = 0; i < nmrCols; i += 1) {
- var $li = $('<li />'),
- $a = $('<a />').attr('href', 'javascript:;').text(i + 1);
- $li.append($a).appendTo($nav);
- $a.click(function (i) {
- return function () {
- $cols.animate({
- left: -colWidth * i + 'px'
- }, 250);
- };
- }(i));
- }
- });
- };
- }(jQuery));
Add Comment
Please, Sign In to add comment