cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  
<h1>Responsive Magic Line Pagination</h1>

<div class="mainbox">
  
  <div class="pgn">
    <ul class="pgn__list" role="navigation" aria-labelledby="paginglabel">
      <li class="prev" title="Previous Page">
        <a href="#" rel="prev"><i class="pgn__prev-icon icon-angle-left"></i><span class="pgn__prev-txt">Previous</span></a>
      </li>
      <!--<li class="prev" title="Previous Page"></li>-->
      <li class="pgn__item">
        <a href="#">3</a>
        <a href="#">4</a>
        <strong class="current">5</strong>
        <a href="#">6</a>
        <a href="#">7</a>
      </li>
      <li class="next" title="Next Page">
        <a href="#" rel="next"><i class="pgn__next-icon icon-angle-right"></i><span class="pgn__next-txt">Next</span></a>
      </li>
      <!--<li class="next" title="Next Page"></li>-->
    </ul>
  </div><!-- /.pagination -->

  <div class="browsers">
    <h2>Supported Browsers:</h2>
    <ul>
      <li class="chrome">Chrome</li>
      <li class="firefox">Firefox</li>
      <li class="safari">Safari</li>
      <li class="opera">Opera</li>
      <li class="ie">IE 9+</li>
    </ul>
  </div>
  <div class="credit">
    <h2>Credit:</h2>
    <ul>
      <li><a href="https://css-tricks.com/jquery-magicline-navigation/" target="_blank">https://css-tricks.com/jquery-magicline-navigation/</a></li>
    </ul>
  </div>
  <div class="follow">
    <h2>Follow me:</h2>
    <ul>
      <li>Twitter: <a href="https://twitter.com/ryanyudotme" target="_blank">@ryanyudotme</li>
    </ul>
  </div>
  
</div>
  
</div><!-- /.container -->
            
          
!
            
              @import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Droid+Sans:400,700);

/*-- Variables --*/
$white: unquote(#fff);
$grey: #bec2d8;
$purple: #313868;

$pgn-top-border-color: $white;
$pgn-normal-color: $purple;
$pgn-disabled-color: #bec2d8;

$mq-tablet-small: "screen and (min-width: 37.500em)"; // 600px
$mq-tablet: "screen and (min-width: 48.000em)"; // 768px
$mq-desktop: "screen and (min-width: 64.000em)"; // 1024px

$base-font-pixel: 16;

/*-- Placeholder --*/
%list-reset {
  list-style: none;
  margin: 0;
  padding: 0;
}

%clearfix {
  // credit: http://nicolasgallagher.com/micro-clearfix-hack/
  .cf:before,
  .cf:after {
    content: " "; /* 1 */
    display: table; /* 2 */
    line-height: 0;
  }

  .cf:after {
    clear: both;
  }

  /**
   * For IE 6/7 only
   * Include this rule to trigger hasLayout and contain floats.
   */
  .cf {
    *zoom: 1;
  }
}

/*-- Mixins --*/
@mixin font-size($sizeValue: 1) {
  font-size: ($sizeValue * $base-font-pixel) + px;
  font-size: $sizeValue + rem;
}

/*-- General --*/
body {
  font-family: 'Droid Sans', sans-serif;
  background-color: #e1e3f2;
}

h1 {
  color: #313868;
  text-align: center;
  margin-bottom: 100px;

  @include font-size(2.25);
}

h2 {
  color: #5a629b;

  @include font-size(1.25);
}

.container {
  padding: 20px;
}

.mainbox {
  width: 80%;
  margin: 0 auto;
}

// browsers
.browsers {
  margin: 150px 0 50px;
  overflow: hidden;

  ul {
    @extend %list-reset;
  }

  li {
    float: left;
    text-align: center;
    padding-top: 80px;
    margin-right: 25px;
    background-size: 400px;
    background-image: url('http://outdatedbrowser.com/public/imgs/browsers-bg.png');
    background-repeat: no-repeat;

    @include font-size(.8125);
  }

  .chrome {
    width: 67px;
    background-position: -6px -83px;
  }

  .firefox {
    width: 69px;
    background-position: -85px -83px;
  }

  .safari {
    width: 69px;
    background-position: -246px -83px;
  }

  .opera {
    width: 66px;
    background-position: -327px -83px;
  }

  .ie {
    width: 70px;
    background-position: -165px -83px;
  }
}

// credit
.credit {
  margin: 0 0 50px;
}

.clearfix {
  @extend %clearfix;
}

/*-- Pagination --*/
.pgn {
  width: 100%;
  border-top: 3px solid $pgn-top-border-color;
  clear: both;
  
  li {
    float: left;
  }
  
  a,
  span,
  strong {
    float: left;
    text-align:center;
    padding-top: 20px;
    color: $pgn-normal-color;
    
    @media #{$mq-tablet} {
      display: block;
    }
  }
  
  a {
    text-decoration: none;
  }
  
  .prev,
  .next {
    width: 33.33333%;
    
    @media #{$mq-tablet-small} {
      width: 20%;
    }

    a {
      display: block;
      width: 100%;
    }
  }
  
  .prev {
    float: left;
    
    a {
      text-align: left;
    }
  }
  
  .next {
    float: right;
      
    a {
      text-align: right;
    }
  }
}

/* <ul> */
.pgn__list {
  @extend %list-reset;
    
  width: 100%;
  position: relative;
  top: -3px;
}

/* <li> - pagination numbers */
.pgn__item {
  width: 33.33333%;
  
  @media #{$mq-tablet} {
    width: calc(100% - 230px);
  }
  
  a,
  span,
  strong {
    display: none;
    text-align: center;
    width: 100%;
    
    &.current {
      display: block;
      
    }
  }

  a {
    @media #{$mq-tablet-small} {
      display: block;
    }
  }
}

/* prev/next icon */
.pgn__prev-icon,
.pgn__next-icon {
  margin-top: 1px;

  .disabled & {
    color: $pgn-disabled-color;
  }
}

.pgn__prev-icon {
  .fullprevnext & {
    float: left;
  }
}

.pgn__next-icon {
  .fullprevnext & {
    float: right;
  }
}

/* prev/next text */
.pgn__prev-txt,
.pgn__next-txt {
  display: none;

  .disabled & {
    color: $pgn-disabled-color;
  }

  .fullprevnext & {
    display: inline-block;
    padding-top: 0;
  }
}

.pgn__prev-txt {
  .fullprevnext & {
    float: left;
  }
}

.pgn__next-txt {
  .fullprevnext & {
    float: right;
  }
}

.pgn__magic-line {
  background-color: $pgn-normal-color;
  position: absolute;
  height: 3px;
}

            
          
!
            
              ###global Modernizr:true ###
'use strict'

(($) ->
  $.fn.extend
    mgPgnation: (options) ->
      $this = $(this)

      if $this.length
        $mainNav = @children()
        $pgnNav = $this.find('.pgn__item')
        $curNav = $this.find('.current')
        $magicNav = $this.find('a')
        $prevNav = $this.find('.prev')
        $nextNav = $this.find('.next')
        $prevNavText = $prevNav.find('.pgn__prev-txt')

        ### func :: update prev text ###
        updatePrevText = ->
          $prevNavText = $prevNav.find('.pgn__prev-txt')
          $prevNavText.html 'Prev'

        ### func :: calculate width of each page num ###
        calPgnWidth = ->
          # number of visible <a> plus <strong class="current">
          vsbNav = $this.find('.pgn__item a:visible').length + 1
          vsbNavs = vsbNav + 2
          prevWidth = 100 / vsbNavs
          pgnWidth = 100 - prevWidth * 2
          $prevNav.css 'width', prevWidth + '%'
          $nextNav.css 'width', prevWidth + '%'
          $pgnNav.css 'width', pgnWidth + '%'
          # <a> and <strong>
          $pgnNav.find('a, strong').css 'width', 100 / vsbNav + '%'

        ### func :: calculate and display prev/next ###
        # 85px - display full text
        showPrevNext = ->
          prevNavWidth = $prevNav.innerWidth()

          if prevNavWidth > 100
            $this.addClass 'fullprevnext'

            # display Previous
            $prevNavText.html 'Previous'
          else if prevNavWidth < 101 and prevNavWidth > 60
            $this.addClass 'fullprevnext'

            # display Prev
            $prevNavText.html 'Prev'
          else
            $this.removeClass 'fullprevnext'

        ### func :: draw magic line ###
        magicDraw = ->
          # draw init magic line
          $magicLine.width($curNav.width())
          if $curNav.position() != undefined
            $magicLine.css 'left', $curNav.position().left
          
          # assign orig values
          $magicLine.data 'origLeft', $magicLine.position().left
          $magicLine.data 'origWidth', $magicLine.width()
        # END funcs
        
        # create magic line
        $mainNav.append('<li class="pgn__magic-line">')
        
        # declare magic line
        $magicLine = $this.find('.pgn__magic-line')

        # add extra class & element if no prev or next
        prevNavWidth = $prevNav.innerWidth()

        if prevNavWidth > 100
          prevText = 'Previous'
        else
          prevText = 'Prev'

        if !$prevNav.children().length
          $prevNav.addClass 'disabled'
          $prevNav.append '<a rel="prev"><i class="pgn__prev-icon icon-angle-left"></i><span class="pgn__prev-txt">' + prevText + '</span></a>'

        if !$nextNav.children().length
          $nextNav.addClass 'disabled'
          $nextNav.append '<a rel="next"><i class="pgn__next-icon icon-angle-right"></i><span class="pgn__next-txt">Next</span></a>'

        # calculate pgn width
        calPgnWidth()

        # show prev/next
        showPrevNext()

        # draw magic line
        magicDraw()
        
        # when hover
        $magicNav.hover (->
          $el = $(this)
          leftPos = $el.position().left
          newWidth = $el.width()
          
          # animate magic line
          $magicLine.stop().animate
            left: leftPos
            width: newWidth
        ), ->
          $magicLine.stop().animate
            left: $magicLine.data('origLeft')
            width: $magicLine.data('origWidth')
      
        ### Window Resize Changes ###
        window.addEventListener 'resize', ->
          updatePrevText()
          calPgnWidth()
          showPrevNext()
          magicDraw()
  # END mgPgnation()
      
  # call function here 
  $('.pgn').mgPgnation()

) jQuery
            
          
!
999px
Loading ..................

Console