Giter Site home page Giter Site logo

kysebo / sticky-pagination-fixer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from murtaugh/sticky-pagination-fixer

0.0 0.0 0.0 184 KB

Does your site have a sticky header? You should use this script to fix keyboard-based pagination events.

Home Page: http://murtaugh.github.io/sticky-pagination-fixer/

sticky-pagination-fixer's Introduction

The Sticky Pagination Fixer

##Sticky headers are super annoying for spacebar paginators.

Why?

Because sticky headers effectively change the height of the viewport without telling the browser.

So?

Well, browsers use their internal measurement of the viewport's height to determine how tall a "page" is, which it uses to determine how far to scroll when a user hits the space or page down keys.

Again: So?

Take a look at this, a diagram of a normal pagination event:

a diagram of a normal pagination event

The box is the viewport, and the red line is the last thing a reader sees before triggering a "paginate down" event. The browsers' pagination logic is designed so the red line is also the first thing the reader sees after their eyes scan back up.

Now look what happens when a sticky header enters the picture (heh):

a diagram of a pagination event with a sticky header

Because the effective height of the viewport is being altered by the sticky header, it means not only is our red line totally obscured but so are two other lines we haven't even seen yet. The reader now has to scroll back up to see what they missed (if they even notice). If you can't see how annoying this is you might be a horrible monster.

Oh. Ok.

The amount of overlap, of course, varies based on the height of the sticky header in question, but the header will never not interfere to some degree.

##Take over that scroll.

Do your readers a favor and install The Sticky Pagination Fixer. It captures native pagination-related events, recalculates the height of the viewport, and then scrolls the page to the correct point. Here's a demo.

##Some notes.

  • Sometimes we use the space bar for other things, like... entering spaces in text fields. The Sticky Pagination Fixer takes that into account.
  • Sometimes we also use the space bar for play/pause events in media players. This is quite a bit trickier โ€” we'll need to think about this.
  • There are probably some other native behaviors we should be accommodating as well.
  • No jQuery required.
  • You might be thinking, "Aaagh, JavaScript!" Well, stop. If JS isn't available or this script breaks? Scrolling will happen as normal. "Graceful degradation", my friends. (Or "progressive enhancement", if you absolutely must.)

##Some credit.

The idea to finally write this script came from the New York Times site, which recently aded a sticky header and thankfully has a similar feature built in. And thanks to Allen Tan who pointed me to this smooth scrolling script on Stack Exchange.

##Plus: it could use a better name.

Any ideas?

sticky-pagination-fixer's People

Contributors

murtaugh avatar

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.