GithubHelp home page GithubHelp logo

ifightcrime / touch-scroll Goto Github PK

View Code? Open in Web Editor NEW

This project forked from niekjuh/touch-scroll

10.0 2.0 5.0 126 KB

The jQuery touchScroll plugin with horizontal scrolling and some bug fixes. Currently only supports vertical OR horizontal.

License: MIT License

Ruby 3.06% JavaScript 96.94%

touch-scroll's Introduction

touchScroll jQuery plugin

About

touchScroll is a jQuery plugin that provides a way to have inline scrollable content. It mimics the behaviour of scrolling on iOS devices (iPhone, iPod touch and iPad) to solve the problem that position: fixed; does not work in mobile Safari.

  • This plugin has been updated to work with horizontally-scrolling content. Downside is you still can't use both vertical and horizontal together. Vertical scrolling is enabled by default.
  • The code is based on iScroll, but is a simpler (and more accurate) plugin for jQuery.

For a more sophisticated scrolling library, I highly recommend Scrollability, which, although not a jQuery plugin, is a very accurate and capable solution to the same problem.

Example

Using your iOS device (iPhone, iPod touch or iPad), view an example of touchScroll in action at: neave.github.com/touch-scroll/example.html

For an example of a page with a fixed footer, view this page on your iOS device: neave.github.com/touch-scroll/footer.html

Make sure your code uses the same base CSS as provided in these examples.

How to use

$('nav').touchScroll(); // Creates touch-scrollable content for a 'nav' element

$('nav').touchScroll({hScroll: true}); // Switches to horizontal scrolling. (currently only one or the other works)

$('nav').touchScroll({y: 100}); // Change the initial vertical scroll position to 100 pixels down

$('nav').touchScroll({scrollHeight: 1000}); // Manually set height of the scrollable area, useful for dynamically sized pages

$('nav').touchScroll({elastic: false}); // Turn off the elastic-bounce at the end of a scroll movement

$('nav').touchScroll({momentum: false}); // Turn off the momentum when a finger is lifted from the screen

$('nav').touchScroll({elastic: false, momentum: false}); // Turn off both elastic-bounce and momentum

$('nav').touchScroll({touchTags: ['a']}); // Allow the 'a' tag to receive touch events

$('nav').touchScroll('update'); // Refresh the touch-scroll area if content has changed

$('nav').touchScroll('setPosition', 100); // Method to set the content vertical scroll position at any time

var scrollY = $('nav').touchScroll('getPosition'); // Returns the current vertical scroll position in pixels

License

This software is released under the MIT License.

Copyright (c) 2011 Paul Neave, neave.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

touch-scroll's People

Contributors

jalada avatar longlostnick avatar neave avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

touch-scroll's Issues

add boundary event handler options

Add options to add handlers for when the scroll reaches the top/bottom/left/right since scrollTop/scrollLeft doesn't work with this setup.

Fix going out of bounds on xoom

On the xoom the scroll is allowed to go way out of bounds and never returns. I'm thinking this is due to xoom not firing webkitTransitionEnd, but I need to look into it further

If that's the case, hopefully I will be able to find a workaround. Like maybe setting an interval that will check for a certain amount of time (the length of the transition) after the user picks up their finger.

getPosition returns NaN

Thanks for implementing the horizontal scrolling I really appreciate it. It works great and I'll be using it in an iPad app I'm currently writing.

When calling the getPosition function currently it returns a NaN. The problem is that an object is being multiplied by -1

i.e. this.getPosition() returns an object {x:0,y:0} and then it is multiplied by -1

getPosition: function() {
var a = [];
this.each(function() {
a.push(-this.getPosition()); <-- problem here
});
return a;
},

I fiddled around with it for a little bit and a simple fix is to get the object first and then multiply each value inside it by -1.

Here's the code:

getPosition: function() {
var a;
this.each(function() {
a = this.getPosition();
a.x = -a.x;
a.y = -a.y;
});
return a;
},

This way when you call:

var position = $('nav').touchScroll('getPosition');

then you can get both the vertical and horizontal values by saying

position.x // for horizontal
position.y // for vertical

Again, thanks for making the horizontal version of this plugin public and hopefully the code above helps make it even better.

Nik

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.