Switch your nav's design on the fly

Overview

Midnight

A jQuery plugin that switches between multiple header designs as you scroll, so you always have a header that looks great with the content below it.

Check out the demo (watch the logo as you scroll).

Installation

Midnight is available on Bower and NPM as midnight.js:

bower install midnight.js

npm install midnight.js

Quick start

Create your fixed nav (or header) as you typically would. For an example, something like this (you can use whatever markup suits you)

<nav class="fixed">
  <a class="logo">Logo</a>
</nav>

Make sure the header works well with position:fixed

After that, take any sections of your page that need a different nav and add data-midnight="your-class" to it, where your-class is the class you are going to use to style that header. If you don't use the property or just leave it blank, the .default header will be used for that section.

<section data-midnight="white">
  <h1>A section with a dark background, so a white nav would look better here</h1>
</section>

<div data-midnight="blue">
  <h1>A blue nav looks better here</h1>
</div>

<footer>
  <h1>This will just use the default header</h1>
</footer>

Multiple headers as necessary will be created based on the classes declared in these sections.

You can style it in your css using the class .midnightHeader.your-class (replace your-class with the correct one). For example:

.midnightHeader.default {
  background: none;
  color: black;
}
.midnightHeader.white {
  background: white;
  color: black;
}
.midnightHeader.blue {
  background: blue;
  color: white;
}
.midnightHeader.red {
  background: red;
  color: white;
}

To initialize, just load midnight and initialize it

<script src="midnight.jquery.js"></script>
<script>
  // Start midnight
  $(document).ready(function(){
    // Change this to the correct selector for your nav.
    $('nav.fixed').midnight();
  });
</script>

Using custom markup

Let's say you want to create a special header with a butterfly in it, which needs some extra markup. You need to do two things:

  • First, add a div with the class .midnightHeader.default . This will be the header that's used for every section (that doesn't have a specific style) and duplicated as necessary, automatically replacing .default with the correct class.

  • Then, add a div with the class .midnightHeader.your-class (like .butterfly). This will be used in that case instead, so you can use some custom markup in that case. Repeat this step for any other header with custom markup.

  • Keep in mind that all headers need to be the same height. Take that into account when styling your headers. If you have one that's larger than usual, we recommend you make all the headers the same height and try to handle it with additional markup.

<nav class="fixed">
  <!-- Your standard header -->
  <div class="midnightHeader default">
    <a class="logo">Logo</a>
  </div>

  <!-- A header with a butterfly -->
  <div class="midnightHeader butterfly">
    <a class="logo">Logo</a>
    <span class="a-butterfly"><!-- Everybody loves butterflies! --></span>
    <span class="another-butterfly"><!-- OH GOD THEY ARE IN MY FACE --></span>
    <span class="yet-another-butterfly"><!-- AAAAAHHHHHHHHHHHHHHHHHHHHH --></span>
  </div>
</nav>

Options

You can use a variety of custom options when using midnight:

$('nav').midnight({
  // The class that wraps each header. Used as a clipping mask.
  headerClass: 'midnightHeader',
  // The class that wraps the contents of each header. Also used as a clipping mask.
  innerClass: 'midnightInner',
  // The class used by the default header (useful when adding multiple headers with different markup).
  defaultClass: 'default'
});

Running Multiple Instances with Different Breakpoints

If you want to run multiple instances of midnight with different breakpoints, you can use the sectionSelector option to choose where each nav is going to be split.

By default, the plugin will look for all the sections with the data-midnight attribute, which is the default, but you can change this to suit your needs. For example:

$('nav.one').midnight({
  // By default, sectionSelector is 'midnight'. It will switch only on elements that have the data-midnight attribute.
  sectionSelector: 'midnight'
});

$('nav.two').midnight({
  // We want this nav to switch only on elements that have the data-noon attribute.
  sectionSelector: 'noon'
});

CDN Hosting

To lower hosting costs & have users load midnight.js faster, you can use the jsDelivr CDN like so:

<script src="//cdn.jsdelivr.net/npm/midnight.js@{version}/dist/midnight.jquery.min.js"></script>

JSDelivr

You can use jsDelivr's version aliasing & concocting to serve the latest minor branch version along with dependancies. For example, to download the latest patch versions of midnight.js v1.0.z together along with jQuery v1.11.z:

<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected]"></script>

Known Issues

On iOS <7 and older Android devices scrollTop isn't updated fluently, which creates a choppy effect. It can be fixed somewhat by wrapping the body in container and detecting touch events, but we're leaving that as an open issue. We'll probably disable the effect on older mobile devices due to bad performance.

You shouldn't add any sort of padding, margin or offset (top/left/right/bottom) to the nav, since it causes issues with rendering.

Comments
  • npm publish

    npm publish

    Hello, could you publish this to npm? You only need to add a main field to package.json and run npm publish

    Also, what is the src file? How is it different from the non-src file?

    opened by fregante 7
  • Overflow:hidden on parent hide the dropdown navbar

    Overflow:hidden on parent hide the dropdown navbar

    Hi, I have one issue with this plugin.When ever i active plugin to my "mainNav" then my "dropDown" show inside the "mainNav" tab. It because "midNight.js" add "overflow:hidden" to my "maiNav".Any solution for that ?

    question 
    opened by arifhussain353 4
  • Logo doesn't appear back after scrolling back to top of the page

    Logo doesn't appear back after scrolling back to top of the page

    Hello and thanks for you plugin!

    I noticed on Edge, when I scroll passed my first "midnight" section and come back to the top of the page, sometimes the logo doesn't appear. It is a strange bug that doesn't happen all the time. Would you happen to know a fix and or an alternative plugin?

    It happens on your demo page on Edge too.

    https://youtu.be/_TtlsxD8lTY

    Thanks!

    opened by amichel86 3
  • Multiple fixed elements

    Multiple fixed elements

    Is it possible to have this work with multiple, different elements fixed in different areas of the page? Think like a left and right sidebar, both transitioning differently as you scroll down the page?

    As it stands, it seems that any data-midnight field I make is being applied to EVERY instance, rather than targeting them to specific elements.

    opened by ekfuhrmann 3
  • author =

    author = "Aerolab" ?

    Glad you're using Releases! Makes it easier for jsDelivr CDN to pull updates automatically :) While setting up your info.ini, it was noticed that the author <> @RobertoGonzalez . Do you want Author field to be "Aerolab" or you please?

    opened by tomByrer 3
  • Not firing check on AJAX page soft-refresh load.

    Not firing check on AJAX page soft-refresh load.

    I've got midnight working great, but it's not firing .midnight() again after an AJAX page load, even when calling the function again on complete. The elements that are being applied midnight aren't reloading on page change.

    opened by wearelfb 2
  • ES6 Module import

    ES6 Module import

    Hello.

    I'm trying to import midnight.js into my file where i execute whole action.

    I try import 'midnight.js/midnight.jquery.js'; import 'midnight.js etc...

    I use webpack to bundle my code. new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }),

    and getting error: $(...).midnight is not a function

    node 6.11.5 yarn 1.0.1 midnight.js 1.1.1

    opened by fstodulski 2
  • Not working with jquery-lang-js

    Not working with jquery-lang-js

    Hello, I am using Midnight on my website (development not production yet) and I am also using https://github.com/Irrelon/jquery-lang-js . There is an issue with these two things together, switching language changes the language only on the first (default) midnight navigation instance, every other midnight nav then contains default language. Any idea on how to fix this? I noticed midnight makes some nested divs that are clones of the original navigation element, the nested elements contain the lang attribute but seem to not change.. is there a way to call a jquery-lang init upon switching midnight headers? something like a callback on complete or something? That would probably fix it.

    opened by jdckl 2
  • How to change the Header Title?

    How to change the Header Title?

    Lame question - i tried editing the midnight.js website(of aerolab obviously) and had a hard time changing the title (you know the "MIDNIGHT.JS" with a moon) to my choice but in vain.

    Really accept some help. Ty ahead

    opened by abhiklodh 2
  • [SOLVED] Sidr JS Menu not working under Midnight.js?

    [SOLVED] Sidr JS Menu not working under Midnight.js?

    Been battling with this plugin as it seems that sidr menu button works until midnight is initiated.

    DEMO: http://bit.ly/1Nclrch

    Try clicking menu when loaded, it works, then scroll down and it starts midnights new header class, now it doesn't. Any good way of fixing this issue? Tried looking around in console and everywhere but cant seem to find why it wont work.

    opened by DylanOpet 2
  • Global scope pollution

    Global scope pollution

    There are several places where variable definitions lick into global scope. For example:

    for( ix in sections ) { ... }
    

    In the above example ix variable should be declared with var keyboard, otherwise ix becomes global variable.

    opened by dfsq 2
  • midnight.js is slows down

    midnight.js is slows down

    hello, I have a fixed navigation {

    <nav class="navbar">
           <div class="container-menu">
                 <a href="#" class="navbar-brand">
                      <img src="{% static '--------------------'%}" alt="" class="logo-little">
                  </a>
                  <div class="navbar-wrap">
                      <ul class="navbar-menu">
                              <li><a href="#">------------</a></li>
                              <li><a href="#">---------</a></li>
                              <li><a href="#">------</a></li>
                              <li><a href="#">--------</a></li>
                       </ul>
                   </div>
                    <div class="navbar-finder">------------</div>
             </div>
    </nav>
    

    } And i also use swiper.js in the project and there is a rather noticeable delay when changing the text color.

    opened by Owlcattt 0
  • Adds horizontal functionality

    Adds horizontal functionality

    Add parameter to use midnight.js vertically or horizontally.

    Upgrade dependencies.

    Autogenerate minified compilation header from file.

    Add script to execute gulp build.

    opened by betoksoft 0
  • Bump jquery from 1.11.3 to 3.5.0

    Bump jquery from 1.11.3 to 3.5.0

    Bumps jquery from 1.11.3 to 3.5.0.

    Commits
    • 7a0a850 3.5.0
    • 8570a08 Release: Update AUTHORS.txt
    • da3dd85 Ajax: Do not execute scripts for unsuccessful HTTP responses
    • 065143c Ajax: Overwrite s.contentType with content-type header value, if any
    • 1a4f10d Tests: Blacklist one focusin test in IE
    • 9e15d6b Event: Use only one focusin/out handler per matching window & document
    • 966a709 Manipulation: Skip the select wrapper for <option> outside of IE 9
    • 1d61fd9 Manipulation: Make jQuery.htmlPrefilter an identity function
    • 04bf577 Selector: Update Sizzle from 2.3.4 to 2.3.5
    • 7506c9c Build: Resolve Travis config warnings
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by mgol, a new releaser for jquery since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Midnight.js not working on horizontal scroll using swiper.js

    Midnight.js not working on horizontal scroll using swiper.js

    Hi there, I'm using swiper.js for a project where I have multiple fullscreen slides. Some slides work horizontally and some work vertically. The vertical ones seem to work find but the horizontal doesn't work at all. Do you know why?

    opened by frazerf 1
Releases(1.1.2)
Owner
Aerolab
We design and develop beautiful digital products for startups and leading brands.
Aerolab
Click effect inspired by Google's Material Design

Waves Click effect inspired by Google's Material Design http://fian.my.id/Waves/ Documentation Waves uses Situs to generate documentation. Here are so

Alfiana Sibuea 3.5k Dec 23, 2022
Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Pure CSS (no JavaScript) implementation of Android Material design "ripple" animation

Mladen Plavsic 334 Dec 11, 2022
Matteo Bruni 4.7k Jan 4, 2023
A library to add a virtual Trackball to your DOM

Trackball.js - 3D Trackballs for your Website Trackball.js is a small JavaScript library on top of Quaternion.js to enable free 3D rotation of element

Robert Eisele 34 Nov 27, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Access the Nintendo Switch Online and Nintendo Switch Parental Controls app APIs.

Access the Nintendo Switch Online and Nintendo Switch Parental Controls app APIs. Includes Discord Rich Presence, friend notifications and data downloads.

Samuel Elliott 201 Jan 6, 2023
Generate fluid, custom property based design systems on the fly — entirely based on Utopia

Fluid Design Systems With Netlify On-demand Builders A proof of concept demonstrating how Netlify on-demand builders can help generate fluid, custom p

George Francis 53 Jan 5, 2023
Switch the background-image with using effect.

jQuery.BgSwitcher Switch the background image with using effect. Demo http://rewish.github.io/jquery-bgswitcher/ Usage <div class="box"> <p>Lorem ip

rewish 195 Dec 30, 2022
NXPayload Converter is a program that allows you to create boot.dat files from Nintendo Switch payload files (.bin)

?? NXPayload Converter NXPayload Converter is a program that allows you to create boot.dat files from Nintendo Switch payload files (.bin) If you have

Murasaki 24 Dec 22, 2022
Streaming and playing on the Nintendo Switch remotely!

Switch-Stream This is a semi-convoluted application as a proof-of-concept that someone could play their Switch from a distance. A server is connected

Charles Zawacki 8 May 2, 2022
Light-switch-bootstrap - Dark mode toggle for Bootstrap 5

?? Light Switch for Bootstrap 5 Basic Bootstrap 5 custom checkbox to use night mode in your web site. Under the hood Switching to dark mode is done by

Han 35 Jan 2, 2023
KWin Script to switch to the next or previous non empty virtual desktop

kwin-cycle-non-empty-desktops KWin Script to switch to the next or previous non empty virtual desktop. Installation Method 1: From the KDE Store Go to

Shaan Subbaiah 1 Dec 5, 2022
❤️ A heart-shaped toggle switch component for React.

heart-switch A heart-shaped toggle switch component for React. Inspired by Tore Bernhoft's I heart toggle Dribbble shot. ?? Table of Contents ?? Getti

Anatoliy Gatt 413 Dec 15, 2022
Automatically switch Terminal profile based on dark / light mode

auto-terminal-profile Automatically switch the macOS Terminal profile based on the system-wide dark / light appearance mode Prerequisites Node.js 14-1

Patrik Csak 17 Jan 2, 2023
Switch case syntax for Svelte ✨

Svelte switch case Switch case syntax for your Svelte components. Demo · StackBlitz · NPM Package ⚡ Getting started Step 1: Add the preprocessor to yo

Lucas Portet 91 Dec 30, 2022
Pure CSS toggle switch

Pure CSS toggle switch demo install npm i toggle-switch-css or yarn add toggle-switch-css use <label class="toggle-switch my-toggle-switch"> <in

magic-akari 6 Sep 14, 2021
switch Alternate Style Sheets

alternate-stylesheets.js switch Alternate Style Sheets Installation npm $ npm install alternate-stylesheets yarn $ yarn add alternate-stylesheets Usag

sasaplus1 1 Dec 11, 2021
Storybook Addon Root Attributes to switch html, body or some element attributes (multiple) at runtime for you story

Storybook Addon Root Attributes What is this This project was inspired by le0pard/storybook-addon-root-attribute The existing library received only on

정현수 5 Sep 6, 2022