GithubHelp home page GithubHelp logo

wickynilliams / headroom.js Goto Github PK

View Code? Open in Web Editor NEW
10.9K 10.9K 828.0 699 KB

Give your pages some headroom. Hide your header until you need it

Home Page: https://wicky.nillia.ms/headroom.js/

License: MIT License

JavaScript 70.74% HTML 29.26%

headroom.js's People

Contributors

andreivictor avatar andyhot avatar burkovsky avatar davidkaneda avatar dvorapa avatar hacknug avatar homerjam avatar irazasyed avatar jamesmosier avatar jefkoslowski avatar kkirsche avatar kmc059000 avatar maliayas avatar matthewnessworthy avatar mjackson avatar nedbaldessin avatar peterdavehello avatar pitr avatar pollyg312 avatar r00dy avatar robertfausk avatar sweetroll avatar talater avatar toddmotto avatar websirnik avatar wendy avatar wickynilliams avatar zwacky 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  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

headroom.js's Issues

Confused on Mobile Support

Hello, I have been trying for several hours to get this working for iOS 7 on both an ipad and iphone with fixed postition header. My site consists of 5 100% divs and I have tried both the pure js and jQuery approach. With the Jquery method, it worked on my ipad and not iphone. The JS way didn't work for either, only my dekstop. Would extra things be needed to make this work besides your scripts and initiating by the element? I did try disabling all other js and it made no difference and I'm using jQuery 2.0.0. Any help would be greatly appreciated. This is the site http://bit.ly/1eGCShX and it should be working

Add tolerance options

Add a tolerance to scrolling so that little movements do not trigger lots of repaints

Mobile support (no android support?)

Hi,

Used this plugin a while back and did some mobile browser tests at that time. The plugin didn't seem to support android.

Android
Android 2.1 and below -> no fixed position
Android 2.2/2.3 - User scalable 0 + fixed position -> works but no headroom JS
Android 3+ - Fixed position works but no headroom JS

iOS
iOS 3/4 fixed position doesn’t work (applies fixed as static)
iOS 5.1 fixed position works but no headroom JS
iOS 6 fixed position works and headroom JS works
iOS 7 fixed position works and headroom JS works

Let me know what you think and what your experiences are. :)

Why i get this error on AngularJS?

Expression '{pinned:'showme',unpinned:'hideme',initial:'headroom'}' used with directive 'headroom' is non-assignable!

I get this error message with classes attribute. How can i avoid it?

Angular.js directive

Could you please add an angular.js directive that will integrate with the standalone widget?

demo playgroom - no effect - TypeError

Hello, i get the following error on your demo page:

TypeError: 'undefined' is not a function (evaluating 'this.update.bind(this)')

Browser:
Safari/webkit

offset should be >= scrollY

Windows' non-smooth scrolling with mouse wheel means that if offset % (1 turn of mouse) == 0 the element may never get pinned, without further scrolling down

Bower support.

Hey.

Would be really nice to download this via bower.

IE7 / IE8 compatibility

HI,

I am trying to use headroom in IE7 and IE8 and a new error is thrown:
Line 100: this.debouncer = new Debouncer(this.update.bind(this));
It looks there is a compatibility problem with bind method.

Is there any solution to make this magnific script compatible with all IE versions from 7?

Thanks.

LICENSE?

you must include license text for MIT license

[Suggestion] Remove all classes when scroll to top

First of all, great plugin.

Second, a suggestion. Currently it works like this, header has no class, when scrolling down a class is added and when scrolling up a class is substituted. My suggestion would be to remove all classes when you scroll to the page top. In that case you can have a header without a background, give it a background when scrolling up and down and when you are back at scroll Y 0 the background is removed (due to the scrolling classes being removed.)

Would do it myself but I'm horrible at JS

Possible improvements

You might get a more natural flow by alternating between absolute and fixed positioning. Start with position: absolute, as you scroll down. On scroll up start, set an absolute position to top: element height * -1. When element position == window position, set to position: fixed, top: 0. And then reverse logic on scroll down.

This would mimic mobile browser address bar behavior. Sorry I can't PR right now, but thought I'd make the suggestion.

How can we use callbacks ?

Hello, I heard there's callbacks now in this awesome script. I want to use the callbacks for execute an action on unpin. I found nothing in the docs explaining how to do it, so, can I have some explaination on how to use them ?

PS: Sorry for my bad english, I'm a french student.

A different approach, set the header top as scroll changes

I edited your very cool plugin to make the header show/hide like the browser top URL bar, by changing the top position according the scroll.

Here my update method:

update : function() {
      var currentScrollY  = this.getScrollY(),
        toleranceExceeded = this.toleranceExceeded(currentScrollY);

        var actualY = parseInt(this.$elem.css('top')),
            newY    = actualY + this.lastKnownScrollY - currentScrollY;
            newY    = Math.max(Math.min(newY, 0), -this.$elem.height());

            this.$elem.css('top', newY + 'px');

clearTimeout(this.unpinTimer);

      this.unpinTimer = setTimeout((function($elem)
      {
          return function()
          {
            var elemHeight  = parseInt($elem.height()),
                actualY     = parseInt($elem.css('top'));

            if (actualY < -elemHeight/2)
            {
                $elem.css('top', -elemHeight + 'px');
            }
            else
            {
                $elem.css('top', '0px');
            }
        };
      }
      )(this.$elem), 200);

      this.lastKnownScrollY = currentScrollY;
    },

Target scrolling within a div

Many mobile websites have Facebook-style slidein menus and the main content div slides over to make room for those menusIn that case, the window doesn't scroll, but the main content div has a height of 100% and the content scrolls within that relatively or absolutely positioned div. (see snap.js as an example).

Is there a way to target the scrolling within a main div, rather than the window itself?

Not working with Joomla Template

I tried to add headroom plugin

// headroom jQuery Plugin $doc->addScript($dcTemplatePath.'/js/headroom.min.js', 'text/javascript');

and than

<script> // grab an element var myElement = document.querySelector("header"); // construct an instance of Headroom, passing the element var headroom = new Headroom(myElement); // initialise headroom.init(); </script>

to my header <header class="headroom">test</header>

I am not using any CSS Style because there is no such documents for this.

Please update readme file with clear concept how to use it.

Prevent pinning on anchor jumps?

Is there any way to prevent pinning on anchor jumps to a higher part of the page, so anchors don't get obstructed by a pinned header?

CSS documentation hints

Thanks for creating this. It works great. But I had to work on it for quite a while before I figured out that I had to add the CSS. I initially interpreted the instructions for jQuery in a literal way:

// simple as this!
// NOTE: init() is implicitly called with the plugin
$("# header").headroom();

So, that's all I did. And indeed, it was quite simple. But although I could see the classes changing on scroll, nothing happened. So, eventually I figured out that -- at least, in my case -- I had to create and add the CSS for the classes:

.headroom {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transition: all .2s ease-in-out;
}
.headroom--unpinned {top: -100px;}
.headroom--pinned {top: 0;}

I'm not sure if the method I used is correct, or if this is supposed to work by following the "simple as this!" guideline in the docs. But it did not work out of the box for me, and if the CSS is required, maybe that could also be shown in the documentation?

Add offset option

Allow an option to set an offset so that the pin/unpin only takes effect so far down the page

Headroom is not defined

Added jquery.headroom.js and headroom.js to my html. Called plugin in headroom.js with:

$("header").headroom({
"tolerance": 5,
"offset": 205,
"classes": {
"initial": "animated",
"pinned": "bounceInDown",
"unpinned": "bounceOutUp"
}
});

Getting 'Uncaught ReferenceError: Headroom is not defined' in console.

Ability to remove class headroom--pinned, when reaches the top of page

Hey,

Great work on this! One question, is there anway when you go back all the way up to top the top of the page, remove the .headroom--pinned class, or infact, better yet, add a new class "headroom-top". That way, with css, I can remove the fixed position.

My reason being, for those that have a different design approach on the top head.

Any help will be appreciated, thanks!

Trigger events when pinned/unpinned

Hi!

It would be awesome to get an event on the header element node telling you it was pinned or unpinned. some additional actions might be desirable in JS when pinning/unpinning occurs

Improve documentation

  • Better README
  • Github pages
  • Examples - offset, tolerance, custom css classes, jQuery plugin, raw object
  • Support list in docs

Support-wise:

  • classList - IE10, android 3
  • rAF - IE10, safari 6, iOS6,
  • bind - IE9

graceful degredation

Will likely fail catastrophically in older browsers. Need some kind of early exit.

Test for:

  • function(){}.bind
  • "classList" in document.documentElement
  • requestAnimationFrame

All of these can be polyfilled for older browsers

Add more classes to options

Hi,

I can't seem to add more than one class onto the options classes of headroom:

$("#menu").headroom({
  "tolerance": 0,
  "offset": 0,
  "classes": {
    "initial": "headroom animated",
    "pinned": "headroom--pinned slideDown",
    "unpinned": "headroom-unpinned slideUp"
  }
});

Any way of resolving this issue?

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.