cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

jQuery Panelize Plugin Concept

A Pen By Captain Anonymous

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.

            
              #header
  %nav
    %a{:href => "#panelOne"} Panel One
    %a{:href => "#panelTwo"} Panel Two
    %a{:href => "#panelThree"} Panel Three
    %span#location
.panelize
  %section#panelOne.panel.one
    %article
      .container
        %header
          %h1 Panel One
        .content
          %p It's a fez. I wear a fez now. Fezes are cool. Sorry, checking all the water in this area; there's an escaped fish. No, I'll fix it. I'm good at fixing rot. Call me the Rotmeister. No, I'm the Doctor. Don't call me the Rotmeister.
          %p I'm the Doctor. Well, they call me the Doctor. I don't know why. I call me the Doctor too. I still don't know why. I hate yogurt. It's just stuff with bits in. I hate yogurt. It's just stuff with bits in. All I've got to do is pass as an ordinary human being. Simple. What could possibly go wrong?
  %section#panelTwo.panel.two
    %article
      .container
        %header
          %h1 Panel Two
        .content
          %p I am the Doctor, and you are the Daleks! Annihilate? No. No violence. I won't stand for it. Not now, not ever, do you understand me?! I'm the Doctor, the Oncoming Storm - and you basically meant beat them in a football match, didn't you? Aw, you're all Mr. Grumpy Face today. It's a fez. I wear a fez now. Fezes are cool. The way I see it, every life is a pile of good things and bad things.…hey.…the good things don't always soften the bad things; but vice-versa the bad things don't necessarily spoil the good things and make them unimportant. Annihilate? No. No violence. I won't stand for it. Not now, not ever, do you understand me?! I'm the Doctor, the Oncoming Storm - and you basically meant beat them in a football match, didn't you?
          %p You hit me with a cricket bat. You know when grown-ups tell you 'everything's going to be fine' and you think they're probably lying to make you feel better? You hit me with a cricket bat. Annihilate? No. No violence. I won't stand for it. Not now, not ever, do you understand me?! I'm the Doctor, the Oncoming Storm - and you basically meant beat them in a football match, didn't you?

          %p I hate yogurt. It's just stuff with bits in. You know how I sometimes have really brilliant ideas? You hit me with a cricket bat.
  %section#panelThree.panel.three
    %article
      .container
        %header
          %h1 Panel Three
        .content
          %p I am the last of my species, and I know how that weighs on the heart so don't lie to me! I am the last of my species, and I know how that weighs on the heart so don't lie to me! It's art! A statement on modern society, 'Oh Ain't Modern Society Awful?'! Stop talking, brain thinking. Hush. I'm the Doctor, I'm worse than everyone's aunt. *catches himself* And that is not how I'm introducing myself. No, I'll fix it. I'm good at fixing rot. Call me the Rotmeister. No, I'm the Doctor. Don't call me the Rotmeister.
          %p Annihilate? No. No violence. I won't stand for it. Not now, not ever, do you understand me?! I'm the Doctor, the Oncoming Storm - and you basically meant beat them in a football match, didn't you? Did I mention we have comfy chairs? No, I'll fix it. I'm good at fixing rot. Call me the Rotmeister. No, I'm the Doctor. Don't call me the Rotmeister. You know how I sometimes have really brilliant ideas? *Insistently* Bow ties are cool! Come on Amy, I'm a normal bloke, tell me what normal blokes do!
            
          
!
            
              @import compass

/////////////////
// Styles Here //
/////////////////

#header
    position: fixed
    z-index: 2000
    background-color: rgba(0,0,0,.4)
    width: 100%
    nav
        max-width: 900px
        margin: 0 auto
    a
        color: white
        display: inline-block
        text-align: center
        padding: 10px 20px
        text-decoration: none
        &:hover, &.active
            background-color: rgba(0,0,0,.7)

#position-block
    position: fixed
    z-index: 1000
    color: white
h1
    font-family: 'Dosis'
    font-style: normal
    font-weight: 600
    color: white
    font-size: 69px
    line-height: 78px
    padding: 20px 0px 10px 20px
    margin: 0

p
    font-family: 'Ubuntu'
    font-style: normal
    font-weight: 400
    color: white
    font-size: 15px
    line-height: 28px
    margin-top: 0px
    text-align: justify

article
    position: relative
    +box-shadow(black 0px 0px 15px)
    header
        padding-top: 30px
    .content
        +column-count(2)
        +column-gap(60px)
        padding: 0 20px 60px 20px
    .container
        max-width: 900px
        margin: 0 auto

.panel
    position: relative
    width: 100%

.panel.one
    article
        background-color: #00AEFF

.panel.two
    article
        background-color: #292929

.panel.three
    article
        background-color: #FF3500
            
          
!
            
              (($, window, document, undefined_) ->
    Panelize = {
        init: (elements, options) ->
            self = @
            # get default elements for rest of plugin
            self.options = $.extend({}, $.fn.panelize.options, options)
            self.outerContainer = elements
            self.panels = elements.children()
            if self.options.containerSelector isnt null
                self.innerContainers = elements.find(self.options.containerSelector)
            else
                self.innerContainers = self.panels.children()
                self.options.containerSelector = self.innerContainers.first().prop('tagName')

            # set z-index properties for panel elements
            count = self.options.startZ
            self.panels.each ->
                $(@).css('z-index', count)
                count -= self.options.zStep
                return

            # set default height for panels
            self.resize()

            self.panels.css({
                'padding-bottom': $(window).height()
                'position': 'fixed'
                'left': 0
                'top': 0
            }).addClass('static')


            self.panels.first().css('position', 'relative').removeClass('static').addClass('scroll')
            self.panels.last().css('padding-bottom', 0)

            lastPosition = 0

            $(window).on 'scroll', ->
                position = $(@).scrollTop()
                #$('#location').html('Top: '+ $(@).scrollTop())
                $element = $('.scroll').last().find(self.options.containerSelector)
                if(position > lastPosition)
                    # down
                    if(($element.offset().top + $element.outerHeight()) <= position)
                        staticPanels = $('.static')
                        $('.scroll').last().css 'padding-bottom', 0
                        if(staticPanels.length is 1)
                            $('.static').first().addClass('scroll').removeClass('static').css {
                                'position': 'relative'
                                'padding-bottom': 0
                            }
                        else
                            staticPanels.first().addClass('scroll').removeClass('static').css {
                                'position': 'relative'   
                            }
                else
                    #up
                    if($element.offset().top > position)
                        scroll = $('.scroll')
                        if(scroll.length > 1)
                            scroll.last().addClass('static').removeClass('scroll').css 'padding-bottom', $(window).height()
                            $('.static').first().css 'position', 'fixed'

                lastPosition = position
                return

            $(window).resize ->
                clearTimeout resizeDelay
                resizeDelay = setTimeout(self.resize(), self.options.resizeDelay)
                return

            return self.outerContainer

        slide: (id) ->
            self = @
            curPos = $(window).scrollTop()
            dest = self.locations[id]
            time = (Math.abs(curPos - dest) / self.options.speed) * 1000
            $('html,body').animate {
                scrollTop: dest
            }, time
            return self.outerContainer
        resize: ->
            self = @
            self.setHeights()
            setTimeout (->
                self.setOffsets()
            ), 100
            return self.outerContainer
        setHeights: ->
            self = @

            # Set minimum heights for panels to match browser height
            self.innerContainers.css('min-height', $(window).height())
            self.outerContainer.css('min-height', self.getOuterHeight())
            return self.outerContainer
        setOffsets: ->
            self = @

            # Get top offsets fore each panel. This will be used
            # for scrolling between panels
            self.locations = {}
            startingPos = 0
            self.panels.each ->
                height = $(@).find(self.options.containerSelector).outerHeight()
                startingPos += height
                self.locations['#'+$(@).attr('id')] = startingPos - height
                return
            return self.outerContainer
        getOuterHeight: ->
            self = @
            height = 0
            self.innerContainers.each ->
                height += $(@).outerHeight()
                return
            return height

    }

    $.fn.panelize = () ->
        if not $.fn.panelize.instance?
            $.fn.panelize.instance = Object.create(Panelize)
        if typeof arguments[0] is 'object' or arguments[0] is undefined
            return $.fn.panelize.instance.init(@, arguments[0])
        else if arguments[0] is 'resize'
            return $.fn.panelize.instance.resize()
        else if arguments[0] is 'slide' and arguments[1]?
            return $.fn.panelize.instance.slide(arguments[1])
        else
            $.error('Method '+method+' does not exists on jQuery.panelize');


    $.fn.panelize.options = {
        containerSelector: null
        speed: 1000
        startZ: 1000
        zStep: 50
        resizeDelay: 300
    }
) jQuery, window, document


$(document).ready ->

    $panels = $('.panelize').panelize({
        containerSelector: 'article'
        speed: 2000
        startZ: 1000
        zStep: 50
    })

    $nav = $('#header a')
    $nav.click (e) ->
        e.preventDefault()
        $nav.removeClass('active')
        $(@).addClass('active')
        $panels.panelize('slide', $(@).attr('href'))
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console