Coder Social home page Coder Social logo

fredericrezeau / inobounce Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lazd/inobounce

0.0 1.0 0.0 47 KB

Stop your iOS webapp from bouncing around when scrolling

Home Page: http://blog.lazd.net/iNoBounce/

License: BSD 2-Clause "Simplified" License

JavaScript 100.00%

inobounce's Introduction

iNoBounce

Stop your iOS webapp from bouncing around when scrolling

The problem

You've built a nice full-screen mobile webapp, complete with scrollable elements using the -webkit-overflow-scrolling property. Everything is great, however, when you scroll to the top or bottom of your scrollable element, the window exhibits rubber band-like behavior, revealing a gray tweed pattern. Sometimes, your scrollable element doesn't scroll at all, but the window still insists on bouncing around.

The solution

No dependencies, no configuration, just include iNoBounce.

<script src="inobounce.js"></script>

Example

All you need is an element with height or max-height, overflow: auto and -webkit-overflow-scrolling: touch.

<script src="inobounce.js"></script>

<style>
    ul {
        height: 115px;
        border: 1px solid gray;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
</style>

<ul>
    <li>List Item 1</li>
    <li>List Item 2</li>
    <li>List Item 3</li>
    <li>List Item 4</li>
    <li>List Item 5</li>
    <li>List Item 6</li>
    <li>List Item 7</li>
    <li>List Item 8</li>
    <li>List Item 9</li>
    <li>List Item 10</li>
</ul>

See the examples/ folder for more examples, including a full-screen list, a canvas drawing app, and a fully skinned iOS-style app.

API

Loading inobounce.js will define the iNoBounce namespace. If the loading environment supports AMD, iNoBounce will register itself as a model and forgo defining the namespace.

  • iNoBounce.enable()
    Enable iNoBounce. It's enabled by default on platforms that support -webkit-overflow-scrolling, so you only need to call this method if you explicitly disable it or want to enable it on a platform that doesn't support -webkit-overflow-scrolling.

  • iNoBounce.disable()
    Disable iNoBounce.

  • iNoBounce.isEnabled()
    Returns a boolean indicating if iNoBounce is enabled.

Will it break my app that uses touch events like other solutions?

It shouldn't. iNoBounce includes an example of a canvas drawing app and has been used in conjunction with Hammer.js without affecting functionality.

How does it work?

iNoBounce detects if the browser supports -webkit-overflow-scrolling by checking for the property on a fresh CSSStyleDeclaration. If it does, iNoBounce will listen to touchmove and selectively preventDefault() on move events that don't occur on a child of an element with -webkit-overflow-scrolling: touch set. In addition, iNoBounce will preventDefault() when the user is attemping to scroll past the bounds of a scrollable element, preventing rubberbanding on the element itself (an unavoidable caveat).

Shoutouts

How can I get that awesome iOS CSS skin from the app example?

Check out iOCSS for a lightweight and easy to use iOS skin for your mobile webapp.

Tapping stuff has a delay, what the heck?

You need FastClick by FT Labs.

Now I want awesome multi-touch gestures too!

It's hammer time, baby. Check out Hammer.js from Eight Media.

License

iNoBounce is licensed under the permissive BSD license.

inobounce's People

Contributors

95b avatar benface avatar davidpett avatar jasonkuhrt avatar lazd avatar stity avatar webpro avatar wolthers avatar

Watchers

 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.