npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

navshrink

v1.5.0

Published

A plugin for use with the navbar component in Bootstrap 3. Shrinks the height and fades in the background of the navbar while scrolling dwn the page

Downloads

3

Readme

NavShrink

NavShrink is a jQuery plugin for your Bootstrap navbar. It works by evaluating scroll position to control the expansion, contraction and color/opacity of the navbar background.

It works in all modern browsers.

Tested with jQuery versions 2.0+

VERSION

v1.5

DEPENDANCIES

Bootstrap 3, jQuery

USAGE

If you are using the Bootstrap navbar component, you can simply include javascript file and init NavShrink with one line:

$('.navbar').navShrink();

Important Note: It is recommended to use the default Bootstrap fixed-top nav structure for this plugin - as seen below.

THE HTML

       <header class="navbar navbar-default navbar-fixed-top">
            <div class="container">
                <div class="navbar-header">
                   <a class="navbar-brand" href="#"><img src="img/logo.png" alt="logo"></a>
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <nav id="bs-navbar" class="collapse navbar-collapse">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">Our Services</a></li>
                        <li><a href="#">Our Products</a></li>
                        <li><a href="#">Who We Are</a></li>
                        <li><a href="#">Get Started</a></li>
                        <li><a class="hamburger hidden-xs" href="#">
                                <span class="bar top"></span>
                                <span class="bar middle"></span>
                                <span class="bar bottom"></span></a>
                        </li>
                        <li><a class="telephone hidden-sm" href="tel:8882225555"><i style="font-size:14px;padding-right:5px;" class="fa fa-phone hidden-lg hidden-md hidden-sm" aria-hidden="true"></i>888-222-5555</a></li>               
                    </ul>
                </nav>
            </div>
        </header>

THE CSS

The CSS is up to you, however, it is strongly recommended that you give your elements default values. In the event that the script does not fire, the nav will fall back on this default state.

a.navbar-brand{
    padding-top:20px; //should match the value used in logoInitPadding
}

a.navbar-brand img {
    height: 74px; //should match the value used in logoInitHeight 
    width: auto;
}

@media (max-width: 768px) {
    a.navbar-brand{
        padding-top:10px;  //should match value used in logoMobilePadding  
    }
    a.navbar-brand img {
        width: auto;
        height:50px; //should match value used in logoMobileInitHeight
    }
} 

NPM

To add navShrink to your project using npm, use the following command:

$ npm install navshrink

OPTIONS

You're also able to use some of the options that let you customize it as you wish:

$('.navbar').navShrink({
anchorInitPadding  : 40, // Before scroll - initial top and bottom padding for your anchors
anchorFinalPadding : 30, // After scroll  - final top and bottom padding for your anchors
logoInitPadding    : 20, // Before scroll - initial padding for the top and bottom of logo
logoFinalPadding   : 12, // After scroll  - final padding for top and bottom of logo
logoInitHeight     : 72, // Before scroll - initial height of logo
logoFinalHeight    : 56, // After scroll  - final height of logo
mobileBreakpoint : 765, // Breakpoint of mobile nav
logoMobilePadding : 10, //Mobile logo top padding
logoMobileFinalHeight : 30, //Before scroll - initial mobile logo height
logoMobileInitHeight : 50, //After scroll - final mobile logo height
bgInitColor        : 'rgba(21,21,21,1)',   // final background color of nav navbar. MUST be in RGBA format.
anchorElem         : '.navbar-nav>li>a',   // anchor elements
navContainer       : this,    // top level element of navbar
logoElem           : 'a.navbar-brand img', // the actual logo element
logoParent         : 'a.navbar-brand',     // the logo container element
defaultOffset      : 80,    // How far down the screen (px) you want the trigger the on reload behavior
speed              : 2,     // The speed at which the transition happens. Higher numbers means faster trasition. 
fadeEnable         : true   // Enables or disables the fade transition effect on the navbar
responsiveEnable : true // Enables or disables responsive mode
});

DOCUMENTATION

Here is the list of available navShrink options:

anchorInitPadding - number | number, default: 40

Set initial padding for top & bottom of your anchors

anchorFinalPadding - number | number, default: 30

Set final padding for top & bottom of your anchors

logoMobilePadding - number | number, default: 10

Set padding for top of your logo on mobile

logoMobileFinalHeight - number | number, default: 30

Set initial height for your logo on mobile

logoMobileInitHeight - number | number, default: 50

Set the final height for your logo on mobile

responsiveEnable - bool | bool, default: true

Enable responsive functionality. Setting to false will disable the responsive logo, requiring you to set the mobile logo height through your CSS. The fade effect will still be applied on mobile. To disable fade, set fadeEnable : false

mobileBreakpoint - number | number, default: 765

Breakpoint of the mobile nav. Should match your Bootstrap small breakpoint

logoInitPadding - number | number, default: 20

Set initial padding for top & bottom of your logo

logoFinalPadding - number | number, default: 12

Set final padding for top & bottom of your logo

logoInitHeight - number | number, default: 72

Set initial height for your logo

logoFinalHeight - number | number, default: 56

Set the final height for your logo

bgInitColor - string | default, 'rgba(21,21,21,1)'

Set the background color for the navbar. This is the color the navbar background will be after scroll completes. Must be in RGBA format.

anchorElem - string | string, default: '.navbar-nav>li>a'

Set the class for your anchor elements

navContainer - string | string, default: this

Set the class for the main navigation container. 'This' refers to the element that the init is bound to, typically '.navbar' or '.navbar-default'

logoElem - string | string, default: 'a.navbar-brand img'

Set the class for your logo element

logoParent - string | string, default: 'a.navbar-brand'

Set the parent container of your logo element

defaultOffset - number | number, default: 80

This should typically be the same as the final height of your navbar. Should the page refresh or reload while the scrollbar is not at top of page, this will force the navbar into its final scroll appearance to prevent style conflicts.

speed - number | number, default: 2

The speed at which the transition occurs. Can be any positive number, including decimals.

fadeEnable - bool | bool, default: true

_Set to false to disable the nav fade effect. Result is similar to responsiveEnable : false, without the need to define height for mobile in your CSS.

DEMO

Check the example here: https://gemlarin.github.io/index.html

TROUBLESHOOTING

navShrink.js is intended to be used with Bootstrap 3's navbar component. If the plugin is not working properly, try the following:

  1. Compare your navbar markup to the provided example. Ensure that the navbar is properly formatted.
  2. IMPORTANT: DO NOT give your navbar a fixed height. Height should be set by applying top and bottom padding to the navbars 'a' tags.
  3. Be sure to presize the logo to match the height designated in the 'logoInitHeight' property. Trying to scale from an oversized image is problematic.
  4. Ensure that the classnames designated in the settings list match the classnames used in your navbar. Recommened to use the navbar version in the demo as your base to ensure proper structure and naming. You can also use your own navbar and pass the correct class names during invocation.
  5. For the logo to shrink, the logo image must be wrapped in a container. It is not necessary to apply any styles to the container, but the container class name that you use must be updated in the settings.

CONTRIBUTION

We still have some issues to fix and make navShrink better, if you have any suggestions raise them in issues please.


MIT Licensed

enjoy!