dist/toolkit.js
function() {
        var options = this.options;

        if (options.calculate) {
            this.calculate();
        }

        if (!this.active) {
            return;
        }

        var eHeight = this.elementHeight,
            eTop = this.elementTop,
            pHeight = this.parentHeight,
            pTop = this.parentTop,
            cssTop = this.initialTop,
            scrollTop = $(window).scrollTop(),
            pos = {},
            x = options.xOffset,
            y = 0;

        // Scroll is above the parent, remove pin inline styles
        if (scrollTop < pTop || scrollTop === 0) {
            if (this.pinned) {
                this.unpin();
            }

            return;
        }

        // Don't extend out the bottom
        var elementMaxPos = scrollTop + eHeight,
            parentMaxHeight = pHeight + pTop;

        // Swap positioning of the fixed menu once it reaches the parent borders
        if (options.fixed) {
            if (elementMaxPos >= parentMaxHeight) {
                y = 'auto';

                pos.position = 'absolute';
                pos.bottom = 0;

            } else if (scrollTop >= eTop) {
                y = options.yOffset;

                pos.position = 'fixed';
                pos.bottom = 'auto';
            }

        // Stop positioning absolute menu once it exits the parent
        } else {
            pos.position = 'absolute';

            if (elementMaxPos >= parentMaxHeight) {
                y += (pHeight - eHeight);

            } else {
                y += (scrollTop - pTop) + options.yOffset;
            }

            // Don't go lower than default top
            if (cssTop && y < cssTop) {
                y = cssTop;
            }
        }

        pos[options.location] = x;
        pos.top = y;

        this.element
            .css(pos)
            .addClass('is-pinned');

        this.pinned = true;

        this.fireEvent('pinned');
    }
function() {
        var options = this.options;

        if (options.calculate) {
            this.calculate();
        }

        if (!this.active) {
            return;
        }

        var eHeight = this.elementHeight,
            eTop = this.elementTop,
            pHeight = this.parentHeight,
            pTop = this.parentTop,
            cssTop = this.initialTop,
            scrollTop = $(window).scrollTop(),
            pos = {},
            x = options.xOffset,
            y = 0;

        // Scroll is above the parent, remove pin inline styles
        if (scrollTop < pTop || scrollTop === 0) {
            if (this.pinned) {
                this.unpin();
            }

            return;
        }

        // Don't extend out the bottom
        var elementMaxPos = scrollTop + eHeight,
            parentMaxHeight = pHeight + pTop;

        // Swap positioning of the fixed menu once it reaches the parent borders
        if (options.fixed) {
            if (elementMaxPos >= parentMaxHeight) {
                y = 'auto';

                pos.position = 'absolute';
                pos.bottom = 0;

            } else if (scrollTop >= eTop) {
                y = options.yOffset;

                pos.position = 'fixed';
                pos.bottom = 'auto';
            }

        // Stop positioning absolute menu once it exits the parent
        } else {
            pos.position = 'absolute';

            if (elementMaxPos >= parentMaxHeight) {
                y += (pHeight - eHeight);

            } else {
                y += (scrollTop - pTop) + options.yOffset;
            }

            // Don't go lower than default top
            if (cssTop && y < cssTop) {
                y = cssTop;
            }
        }

        pos[options.location] = x;
        pos.top = y;

        this.element
            .css(pos)
            .addClass('is-pinned');

        this.pinned = true;

        this.fireEvent('pinned');
    }
function ( ) { var options = this . options ; if ( options . calculate ) { this . calculate ( ) ; } if ( ! this . active ) { return ; } var eHeight = this . elementHeight , eTop = this . elementTop , pHeight = this . parentHeight , pTop = this . parentTop , cssTop = this . initialTop , scrollTop = $ ( window ) . scrollTop ( ) , pos = { } , x = options . xOffset , y = 0 ; // Scroll is above the parent, remove pin inline styles if ( scrollTop < pTop || scrollTop === 0 ) { if ( this . pinned ) { this . unpin ( ) ; } return ; } // Don't extend out the bottom var elementMaxPos = scrollTop + eHeight , parentMaxHeight = pHeight + pTop ; // Swap positioning of the fixed menu once it reaches the parent borders if ( options . fixed ) { if ( elementMaxPos >= parentMaxHeight ) { y = 'auto' ; pos . position = 'absolute' ; pos . bottom = 0 ; } else if ( scrollTop >= eTop ) { y = options . yOffset ; pos . position = 'fixed' ; pos . bottom = 'auto' ; } // Stop positioning absolute menu once it exits the parent } else { pos . position = 'absolute' ; if ( elementMaxPos >= parentMaxHeight ) { y += ( pHeight - eHeight ) ; } else { y += ( scrollTop - pTop ) + options . yOffset ; } // Don't go lower than default top if ( cssTop && y < cssTop ) { y = cssTop ; } } pos [ options . location ] = x ; pos . top = y ; this . element . css ( pos ) . addClass ( 'is-pinned' ) ; this . pinned = true ; this . fireEvent ( 'pinned' ) ; }
Pin the element along the vertical axis while staying contained within the parent.
Pin the element along the vertical axis while staying contained within the parent .