GithubHelp home page GithubHelp logo

istvan-ujjmeszaros / bootstrap-autohidingnavbar Goto Github PK

View Code? Open in Web Editor NEW
321.0 28.0 106.0 47 KB

An extension for Bootstrap's fixed navbar which hides the navbar while the page is scrolling downwards and shows it the other way.

License: Other

JavaScript 100.00%

bootstrap-autohidingnavbar's Introduction

Bootstrap Auto-Hiding Navbar Build Status

Bootstrap Auto-Hiding Navbar is an extension for Bootstrap's fixed navbar which hides the navbar while the page is scrolling downwards and shows it the other way. The plugin is able to show/hide the navbar programmatically as well.

Demo

http://www.virtuosoft.eu/code/bootstrap-autohidingnavbar/

Usage

  1. Download the latest tag from the releases page or get it via bower:
$ bower install bootstrap-autohidingnavbar
  1. Include jQuery and Bootstrap:
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/js/bootstrap.min.js"></script>
  1. Include plugin's code:
<script src="dist/jquery.bootstrap-autohidingnavbar.min.js"></script>
  1. Call the plugin:
$(".navbar-fixed-top").autoHidingNavbar({
  // see next for specifications
});

Specifications

Initialization parameters object

When calling $(".navbar-fixed-top").autoHidingNavbar() you can pass a parameters object with zero or more of the following:

  • disableAutohide, defaults to false, set this to true if you want to show/hide the navbar programmatically.
  • showOnUpscroll, defaults to 'true', the navbar shows up when scrolling the page upwards (otherwise it shows only when scroll is on page's top).
  • showOnBottom, defaults to 'true', the navbar shows up when scroll reaches the page's end.
  • hideOffset, defaults to 'auto', hides the navbar after scrolling that much pixel. Auto means the navbar's height.
  • animationDuration, defaults to '200', is the duration of the show and hide animations in milliseconds.
  • navbarOffset, defaults to '0', the navbar doesn't hide that many pixels from the bottom.

Events

You can listen for following events.

  • show.autoHidingNavbar triggers when element is shown.
  • hide.autoHidingNavbar triggers when element is hidden.
var element = $(selector);

element.on("show.autoHidingNavbar", function() {
  // on show
});

element.on("hide.autoHidingNavbar", function() {
  // on hide
});

Methods

You can modify the behavior and aspect of the plugin by calling its methods, most of them accepts a value.

To call methods on the auto hiding instance, use the following syntax:

$(selector).autoHidingNavbar(methodName, parameter);

Here are the available methods:

  • setDisableAutohide(value) to change the disableAutohide parameter.
  • setShowOnUpscroll(value) to change the showOnUpscroll parameter.
  • setShowOnBottom(value) to change the showOnBottom parameter.
  • setHideOffset(value) to change the hideOffset parameter.
  • setAnimationDuration(value) to change the animationDuration parameter.
  • show() to show the navbar programmatically.
  • hide() to hide the navbar programmatically.
  • destroy() destroys the plugin instance.

Structure

The basic structure of the project is given in the following way:

├── demo/
│   └── index.html
├── dist/
│   ├── jquery.bootstrap-autohidingnavbar.js
│   └── jquery.bootstrap-autohidingnavbar.min.js
├── src/
│   └── jquery.bootstrap-autohidingnavbar.js
├── .editorconfig
├── .gitignore
├── .jshintrc
├── .travis.yml
├── bootstrap-autohidingnavbar.jquery.json
├── bower.json
├── Gruntfile.js
└── package.json

Contains a simple HTML file to demonstrate the plugin.

This is where the generated files are stored once Grunt runs.

Contains the source files.

This file is for unifying the coding style for different editors and IDEs.

Check editorconfig.org if you haven't heard about this project yet.

List of files that we don't want Git to track.

Check this Git Ignoring Files Guide for more details.

List of rules used by JSHint to detect errors and potential problems in JavaScript.

Check jshint.com if you haven't heard about this project yet.

Definitions for continous integration using Travis.

Check travis-ci.org if you haven't heard about this project yet.

Package manifest file used to publish plugins in jQuery Plugin Registry.

Check this Package Manifest Guide for more details.

Contains all automated tasks using Grunt.

Check gruntjs.com if you haven't heard about this project yet.

Specify all dependencies loaded via Node.JS.

Check NPM for more details.

Building

To build and test the plugin, you need:

  • NodeJS with npm
  • bower (install it with npm install bower --g)
  • grunt-cli (install it with npm install grunt-cli --g)

Then, cd to the project directory and install the required dependencies:

$ npm install
$ bower install

To run jshint on the plugin code, call:

$ grunt jshint

To build the output js and css files, with the related minified ones, run:

$ grunt

Issues and Contributions

You can report any issue you may encounter on the GitHub Issue Tracker.

To contribute, please follow the contribution guidelines.

History

Check Release list.

License

  Copyright 2014 István Ujj-Mészáros

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

bootstrap-autohidingnavbar's People

Contributors

bryant1410 avatar dlottich avatar istvan-ujjmeszaros avatar lazyants avatar mariavilaro avatar psychobunny avatar songoo avatar vladimirnani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap-autohidingnavbar's Issues

Breaks dropdown menus?

I just tried implementing this on my personal site and it seems to have broken my dropdowns, so I disabled it. But I'd love for it to work because it looked great, so I'm submitting an issue.

I tried overwriting the bower file to just load the js, but it still wouldn't fire my Bootstrap dropdowns on click. Anyone else experience this? I see the demo site fires the dropdowns on hover...

My site is built using the Roots Sage starter theme for WordPress, which uses the SASS version of BootStrap.

sbt

For some reason few days ago after sbt reload, autohidingnavbar dependency started to downloading boostrap 4.0.0-aplha, which owerride my web 3.3.1 boostrap causing unwanted layout changes.

Not sure what exactly cause it , maybe somehow this bower annotation ? :
"bootstrap": ">=3.0.0"

Yii2 BS4 showOnUpscroll not working

Hi,

I've updated Yii2 to BS4. When I scroll down the page, correctly the navbar menu is hidden, but when I scroll top the page, the navbar menu it's not shown. It seems that the option "showOnUpscroll" is set to false, but I haven't specify it in my plugin init. The navbar menu is shown only when I scroll the page on start. I've tried also to specify "showOnUpscroll: true", but nothing changed.

Plugin init:

$('.navbar-fixed-top').autoHidingNavbar({ showOnBottom: false });

My menu:

<nav id="w0" class="navbar-inverse navbar-fixed-top navbar-expand-md navbar-dark bg-dark collapse show navbar" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggler hidden-sm-up" data-toggle="collapse" data-target="#w0-collapse"><span class="sr-only">Toggle navigation</span>
                &#9776;</button>
            <a class="home-link navbar-brand" href="/DesignazioniProject/Designazioni/web/index.php?r=site%2Fhome">
                <img class="logo" src="/DesignazioniProject/Designazioni/web/css/images/whistle.png" alt="">Designazioni
                <div class="logo_beta">Beta</div>
                <div class="welcome_message">Ciao, Cristian</div>
            </a>
        </div>
        <div id="w0-collapse" class="collapse navbar-toggleable-xs">
            <ul id="w1" class="nav">
                <li class="home-link nav-item"><a class="nav-link" href="/DesignazioniProject/Designazioni/web/index.php?r=site%2Fhome"><i class="fas fa-home" style="padding-right: 10px"></i>Home</a></li>
                ...
                ...
                ...
            </ul>
        </div>
    </div>
</nav>

Many thanks & best regards,
Chris.

Support for multiple plugins on same page

If I try to apply the element to two navbars on the same page only one of they responds to scroll events.

Here is a plnkr that demonstrates this issue. Note I included code from #5 to be able to show with top and bottom nav.

NPM

Would it be possible to publish this to NPM in addition to Bower?

Events

Hi, are the events still supported?

Many thanks,
Chris.

Bug when navbar has top or bottom padding

If change the navbar style adding padding, the script not set the correct measure to hide the navbar.
Fix is really simple: change the height() function at row 43 with innerHeight().

Thank you for your work!

Delay on navbar hiding on mobile Chrome

On mobile chrome the navbar takes a little while to disappear and doesn't work as smoothly as in mobile Safari or desktop versions.

Thanks a lot for this, awesome plugin!

navbar-fixed-bottom??

Is there any way to use it with a navbar fixed at the bottom of the page with the same functionality?

Great work and thanks in advance!

Damian

mobile support ?

Just loaded the test website in a S4 and the demo does not work. Reloaded the demo page a couple of times and cleared the cache. Is this for desktop only?

Events

Hi

I think it would be good if you can add event triggers. So you can hide or show other things than navbar, e.g. logo which is higher than navbar.

usage of mehtods (v.4.0.0)

Hi, thanks for that very useful script - but would you please be so kind to give me a hint how to make work with the methods mentioned on on https://www.virtuosoft.eu/code/bootstrap-autohidingnavbar/. It only works for me using

<script type="text/javascript">$('.fixed-top').autoHidingNavbar();</script>.

Using it with

<script type="text/javascript">$('.fixed-top').autoHidingNavbar('showOnBottom', false);</script> <script type="text/javascript">$('.fixed-top').autoHidingNavbar('showOnBottom' false);</script> <script type="text/javascript">$('.fixed-top').autoHidingNavbar(showOnBottom, false);</script> <script type="text/javascript">$('.navbar-fixed').autoHidingNavbar('setHideOffset', true);</script>

or any other syntay breaks the script.

ps: i tried to ask this on https://www.virtuosoft.eu/code/bootstrap-autohidingnavbar/, but disqus marked my post as spam.

padding above navbar

Works a treat however, my navbar has padding above. Upon reappearing it removes the padding above my navbar and realigns back it to top.
How do i adjust for this padding? (100px on desktop and 50px on mobile)?
Thanks

height not calculated correctly with box-sizing: border-box; and height set

By default bootstrap has box-sizing: border-box; set in the css for anything with a height specified. So, if my navbar starts off with something like :

<header id="header" class="navbar navbar-fixed-top">

and in my css I set a height :

#header {
   height:66px;
   border-bottom:1px solid #000;
   ...
}

the incorrect top position is set in the html when the navbar is hidden :

style="top: -65px;"

when that value should be -66px. The result is the bottom border is shown at the top of the page when the navbar is hidden from view. I'm not sure if this is a fault of the browser or what, but somewhere the calculated height is wrong due to the 1px border and box-sizing: border-box set in the css.

For now I am doing a quick fix, specific to my case, to solve the issue by changing line 43 :

top: -autoHidingNavbar.element.height() - 1

by subtracting an additional 1px to take into account my 1px border set. I haven't done much research into anything else, but I would think there would be a way to properly calculate this dynamically.

input fields on ios causing the navbar to hide

Not sure if this has been going on for awhile now and I never noticed it or this is due to a newer version of this script.

I have a user login dropdown in my nav with two input fields. When the menu is collapsed (iPhone on ios) the menu works fine, BUT as soon as I tap any of the input fields the menu hides. I believe this is due to ios slightly zooming in the screen so the script thinks it scrolled and hides it.

I honestly don't remember this ever happening before as I would think I would have noticed it... plus I usually test things out pretty thoroughly. The only things that have changed recently are :

  • bootstrap 3.3.7
  • jquery 3.1.0
  • this plugin to 1.0.5

I 'think' I previously had 1.0.2 or 1.0.3 installed - I know it didn't have the navbarOffset option. Is there anything in the code since those that would cause this? Possibly the new bootstrap or jquery?

Mobile "hideOffset"

hideOffset, defaults to 'auto', hides the navbar after scrolling that much pixel. Auto means the navbar's height.

Trying to use this, to prevent the bar to show on small scrolls...
on pc works fine, but in mobile android does not ....

Any ideia how to fix ?

Thanks

Add using class or data attribute

Most of Bootstrap's JavaScript works by simply adding a class or data attribute to the concerned element(s). It could be nice to simply be able to use the plugin by adding something like class="navbar-autohide" or changing settings with data attributes.

Disable on small screen

How do I disable it on smaller devices? I used the following code, but no clue.

$(".auto-hiding-navbar").autoHidingNavbar();

$(document).ready(function () {

if ($(window).width() > 992) {

$('.auto-hiding-navbar').autoHidingNavbar('setDisableAutohide', true);

} else {

$('.auto-hiding-navbar').autoHidingNavbar('setDisableAutohide', false);

}

});

dynamic navbar height

Trying something new and running into an issue with the height calculation. Basically if you are at the top of the page the navbar is 100 pixels high, but as you scroll down (past 100 pixels) it becomes smaller to 50 pixels high when shown. I've seen a lot of sites do this to make the navbar, logo, etc stand out on page load, but as the user is scrolling through content it becomes shorter as to not take valuable space from viewing.

To do this I am using some simple js and css media queries. After looking at the code it seems like the navbar height is only calculated once, therefore, any dynamic changes in the height through css aren't picked up. If the height was 100px when jquery.bootstrap-autohidingnavbar.js loads then it will always be 100px. Of course, I can't manually set the hideOffset value either because it is dynamic. I understand the 'auto' value automatically calculates, but I thought maybe it would do so dynamically.

destroy method problem

destroy: function() {
      ...
     // this is AutoHidingNavbar object
     // $.data(this, 'plugin_' + pluginName, null);
     // fix 
     $.data(this.element.get(0), 'plugin_' + pluginName, null);
      ...
    } 

$.fn[pluginName] = function(options) {
...
// this is DOMElement
$.data(this, 'plugin_' + pluginName, new AutoHidingNavbar(this, options)); 
...
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.