> iScroll 4

iscroll4

iScroll finally received a complete rewrite. Now it’s smoother than ever and adds some new important features: pinch/zoom, pull down to refresh, snap to elements and more custom events for a higher level of hackability.


Project info

Last code update: 2011.07.03 – v4.1.7
Device compatibility: iPhone/Ipod touch >=3.1.1, iPad >=3.2, Android >=1.6, Desktop Webkit, Firefox, Opera desktop/mobile.
Discussion group
QR Code opens demo page.

Support development

If this script saved your day and you wish to support future developments you may consider sending some funds via PayPal or Flattr.


Overview

iScroll 4 is a complete rewrite of the original iScroll code. The script development began because mobile webkit (on iPhone, iPad, Android) does not provide a native way to scroll content inside a fixed width/height element. This unfortunate situation prevents any web-app to have a position:absolute header and/or footer and a scrolling central area for contents.

While latest Android revisions are supporting this functionality (although support is not optimal), Apple seems reluctant to add one finger scrolling to divs.

In addition to all previous iScroll features, version 4 introduces:

  • Pinch / Zoom
  • Pull up/down to refresh
  • Improved speed and momentum
  • Snap to element
  • Customizable scrollbars

Please note that iScroll 4 is not a drop-in replacement for iScroll 3. The APIs have changed.

Also consider that the script is still in beta, and some APIs may slightly change.

Getting started

In the archive you’ll find plenty of examples to get you started. Before asking for help, please, look at the demos and read through all this document. I know it’s boring, but it holds all the secrets of the iScroll Ninja.

iScroll needs to be initialized for each scrolling area you need. There’s no limit to the number of iScrolls you can have on any single page, if not that imposed by the device memory/cpu. The type and length of the contents influence the number of iScrolls you can use simultaneously.

Try to keep the DOM structure as simple as possible, remove all the unnecessary tags and avoid too many nested elements.

The optimal iScroll structure is:

<div id="wrapper">
	<ul>
		<li></li>
		...
		...
	</ul>
</div>

In this example the UL element will be scrolled. The iScroll must be applied to the wrapper of the scrolling area.

Important: only the first child of the wrapper element will be scrolled. If you need more elements inside the scroller you may use the following structure:

<div id="wrapper">
	<div id="scroller">
		<ul>
			<li></li>
			...
			...
		</ul>

		<ul>
			<li></li>
			...
			...
		</ul>
	</div>
</div>

In this example the scroller element will be scrolled (together with the two ULs).

iScroll be must instantiated (ie: called for the first time) when the DOM is ready. You have mainly four options:

  • onDOMContentLoaded event
  • onLoad event
  • inline, place the code below the html bit you want to scroll

onDOMContentLoaded

If you have only text and all images have fixed dimensions (ie: explicit width/height) you may use the DOMContentLoaded event.

In the document HEAD add:

<script type="application/javascript" src="iscroll.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
	myScroll = new iScroll('wrapper');
}
document.addEventListener('DOMContentLoaded', loaded, false);
</script>

Note that the myScroll variable is global, so that you can access all the scroller functions from anywhere.

onLoad

Sometimes the DOMContentLoaded is a bit hasty and get fired when the contents are not ready. If you slip into some weird behaviors (eg: rubber band effect), try the following:

<script type="application/javascript" src="iscroll.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
	setTimeout(function () {
		myScroll = new iScroll('wrapper');
	}, 100);
}
window.addEventListener('load', loaded, false);
</script>

In this case iScroll is started only 100ms after the page is completely loaded (graphics included). This is probably the safest way to call the iScroll.

Inline initialization

With this method the iScroll is instantiated as soon as the wrapper and its contents are written to the page. I wouldn’t suggest this approach, but I see many javascript gurus using it… so who am I to disagree?

First of all include the iscroll.js in the page HEAD and then create the iScroll object just below the scroller.

<div id="wrapper">
	<ul>
		<li></li>
		...
		...
	</ul>
</div>

<script type="text/javascript">
var myScroll = new iScroll('wrapper');
</script>

Alternatively you may use your preferred framework ready function (eg:jquery ready()).

Passing parameters to the iScroll

iScroll behavior can be customized with the optional second parameter. Eg:

<script type="text/javascript">
var myScroll = new iScroll('wrapper', { hScrollbar: false, vScrollbar: false });
</script>

The second parameter is always an object. In the example above the scroller won’t show the scrollbars. The most common options you will use are:

  • hScroll, used to disable the horizontal scrolling no matter what. By default you can pan both horizontally and vertically, by setting this parameter to false you may prevent horizontal scroll even if contents exceed the wrapper.
  • vScroll, same as above for vertical scroll.
  • hScrollbar, set this to false to prevent the horizontal scrollbar to appear.
  • vScrollbar, same as above for vertical scrollbar.
  • fixedScrollbar, on iOS the scrollbar shrinks when you drag over the scroller boundaries. Setting this to true prevents the scrollbar to move outside the visible area (as per Android). Default: true on Android, false on iOS.
  • fadeScrollbar, set to false to have the scrollbars just disappear without the fade effect.
  • hideScrollbar, the scrollbars fade away when there’s no user interaction. You may want to have them always visible. Default: true.
  • bounce, enable/disable bouncing outside of the boundaries. Default: true.
  • momentum, enable/disable inertia. Default: true. Useful if you want to save resources.
  • lockDirection, when you start dragging on one axis the other is locked and you can keep dragging only in two directions (up/down or left/right). You may remove the direction locking by setting this parameter to false.

Tips: to preserve resources try to remove the scrollbars (h/vScrollbar option).

Pull to refresh

This feature has become famous thanks to the Twitter app and many other native applications on the Apple Store. You can watch a preview in this screencast.

I’ve recently removed the “pull to refresh” from the script core and replicated the same functionality as an external plugin. Please have a look at the included example to get an idea of how it works.

All you have to do is to customize the pullDownAction() function. You’ll probably need an ajax call that loads new contents, remember to call the refresh method once the new data is attached to the DOM. Also please note that the example adds a 1 second delay to simulate network congestion. Of course you don’t want it in production, so remember to remove the setTimeout.

Pinch / Zoom

Let’s face it: scrolling is boring. That’s why iScroll 4 lets you also zoom in and out. By setting the zoom option to true the scroller reacts to pinch/zoom gestures. Believe your eyes if you don’t believe me.

Double tap to zoom in/out is also supported.

The minimum setup to activate zooming is:
var myScroll = new iScroll('wrapper', { zoom: true });.

You may further customize the zoom behavior with the following option:

  • zoomMax, this is the maximum allowed scale. Defaulted to 4, it means 4 times the original size.

Tip: to have good looking zoomed images place them into the hardware compositing layer. Or –to speak in plain English– apply -webkit-transform:translate3d(0,0,0) to all images that need to be scaled. Important: hardware acceleration takes a lot of resources, use it sparingly or your app will just crash. Don’t say I didn’t warn you.

Snap and snap to element

The snap feature locks the scroller to predefined positions. This can be used to create fancy carousels.

By default iScroll subdivides the scroller into quadrants or pages of the same size of the wrapper. iScroll 4 also adds the option to snap to any element inside the scroller regardless of the wrapper size.

If you wish to create carousels I suggest to use the default “quadrant” subdivision. The perfect setup is:

var myScroll = new iScroll('wrapper', {
	snap: true,
	momentum: false,
	hScrollbar: false,
	vScrollbar: false });

To snap to elements, pass a string representing the query of the DOM elements the scroller should snap to. Eg:

var myScroll = new iScroll('wrapper', {
	snap: 'li',
	momentum: false,
	hScrollbar: false,
	vScrollbar: false });

In this example the scroller will snap to the top left corner of all LI elements inside the scroller.

Note that the snap string is applied to the scroller (ie: scroller.querySelectorAll(snap_string)), so '#scroller li' is wrong, while just 'li' is correct.

Custom scrollbars

You can now customize the scrollbars appearance with a bunch of CSS. To apply a class to the scrollbars you just need to pass the scrollbarClass option:
myScroll = new iScroll('wrapper', { scrollbarClass: 'myScrollbar' });.

In this example the myScrollbarH class will be applied to horizontal bar and myScrollbarV to the vertical bar. Note that the scrollbar is composed by two elements: container and indicator. The container has the same height of the scroller wrapper, while the indicator is the scrollbar itself.

The scrollbar HTML structure:

<div class="myScrollBarV">
	<div></div>
</div>

How to style it:

.myScrollbarV {
	position:absolute;
	z-index:100;
	width:8px;bottom:7px;top:2px;right:1px
}

.myScrollbarV > div {
	position:absolute;
	z-index:100;
	width:100%;

	/* The following is probably what you want to customize */
	background:-webkit-gradient(linear, 0 0, 100% 0, from(#f00), to(#900));
	border:1px solid #800;
	-webkit-background-clip:padding-box;
	-webkit-box-sizing:border-box;
	-webkit-border-radius:4px;
	-webkit-box-shadow:inset 1px 1px 0 rgba(255,255,255,0.5);
}

Have a look at the demo CSS to get an idea.

Public methods

iScroll has some public methods you can access any time to interact with the scroller. The most important of all is refresh, it must be called each time the content inside the scroller changes.

Public methods are accessed thank to the global variable used to instantiate the iScroll. In the examples I used myScroll, so you can access all the methods with: myScroll.name_of_the_function(parameters).

Continue reading for more details.

Mastering the refresh() method

iScroll needs to know the correct dimensions of both the wrapper and the scroller. They are computed the first time at start up but if your code changes the elements size, iScroll needs to be warned that you are messing with the DOM.

This is achieved by calling the refresh function with the right timing. Please follow me closely, understanding this will save you hours of scrolling frustration.

Every time you change elements height/width or you modify the html structure in any way (eg: appendChild or innerHTML) the browser renderer updates the page. Once the browser applied the changes you can access the new DOM (and properties) from javascript again. Sometimes this process is not instant.

To ensure that javascript gets the updated parameters you can force reading the DOM in a new instance. Look at the following code:

ajax('page.php', onCompletion);

function onCompletion () {
	// Here modify the DOM in any way, eg: by adding LIs to the scroller UL

	setTimeout(function () {
		myScroll.refresh();
	}, 0);
};

Here we placed the refresh call into a zero timeout, doing so we gave the browser the time to refresh itself and the new element dimensions are correctly taken. There are other ways to ensure the browser actually updated the DOM, but so far the zero-timeout has proven to be the most solid.

So the golden rule is: if unsure call the refresh inside a timeout.

Javascript scrolling

You can scroll programmatically with scrollTo, scrollToElement and scrollToPage (if your are using the snap feature).

scrollTo(x, y, time, relative) scrolls the wrapper contents to the x/y coordinates in a give timeframe: myScroll.scrollTo(0, -100, 200) position the scroller 100 pixels down in the wrapper within 200 milliseconds.

You can also scroll relatively to the current location by passing the forth parameter: myScroll.scrollTo(0, 10, 200, true). The scroller is shifter by 10 pixels in the y axis starting from the current location.

scrollToElement(element, time) scrolls to any element inside the scrolling area: myScroll.scrollToElement('li:nth-child(10)', 100). This code scrolls to the 10th element in the list. The first parameter is a CSS3 selector or the element node itself.

If snap is active you can also use the snapToPage(pageX, pageY, time) function: myScroll.scrollToPage(1, 0, 200). This will position to the second horizontal page in 200 ms. Pages are zero based (ie: page 1 is 0, page 2 is 1, …).

Destroy!

To completely destroy the iScroll and free some (a lot of) memory, call the destroy() method.

Best way to destroy an iScroll:

myScroll.destroy();
myScroll = null;

iScroll Lite Edition

iScroll is evolving and adding many new features to the basic scrolling functionality. If all you need is the plain old scroller for mobile webkit, you should really use iscroll-lite.js instead.

iScroll Lite is a frippery free version of iScroll 4. It supports scrolling on mobile devices only (no desktop compatibility). Snap, zoom, pull to refresh and superpowers are all stripped away. Fat free, eat as much as you can.

Known issues and future development

The followings are known issues I’m currently working on:

  • Form fields compatibility
  • Zoom glitches
  • Better desktop browser compatibility
  • onScroll event
  • hash and hash change support (ie: http://example.com/#element-id)
  • automatic refresh upon DOM change

Credits

iScroll is evolving thank to the help of all those who sent suggestions, bug reports and ideas on github, here on my blog and googlecode. This is by no means the work of a sole man.

In pure rnd() order: beedesk, Daniel J. Pinter, Aseem Kishore, Alex Gibson, Christoph Pojer, Shimon Dookdin, Will Bailey, Aaron Infidel. (Let me know if I forgot your name).

All those who supported, linked, loved the iScroll.

Projects using/based/inspired by the iScroll library

It became impossible to track all the websites and applications using iScroll. It has been used by Apple, Playboy, People.com, LinkedIn and it is in so many Phonegap’d applications in the Apple store that it is impossible to count them all.

Comments and Support

The blog comments reveled an inadequate system to discuss iScroll features, please use the google discussion group instead.

/Share the joy

/Reactions

    • Author: coskuncc
    • Posted on: 2011/10/21
    • At: 09:50

    my problem is some interesting.

    i used jquery.mobile.scrollview.but it has a problem. its slow.

    i used to iscroll. but it has a problem too.
    its input or textarea or select object is readonly :( . please , help me. how can i do readable when i use iscroll. thank you already

    Reply
      • Author: smarteng
      • Posted on: 2011/11/08
      • At: 02:47

      I have this problem too~~

      Reply
      • Author: justme
      • Posted on: 2011/11/10
      • At: 21:49

      I’m facing the same problem with a textfield.

      Reply
      • onBeforeScrollStart: function (e) {
        var target = e.target;
        while (target.nodeType != 1) target = target.parentNode;
        if (target.tagName != ‘BUTTON’ && target.tagName != ‘SELECT’ && target.tagName != ‘INPUT’ && target.tagName != ‘TEXTAREA’)
        e.preventDefault();
        },

      • Author: Aishwary Mandlik
      • Posted on: 2011/12/19
      • At: 10:14

      Thanks a lot for superb script.. :)

      Now, my script of hiding ‘Address-bar’ is not working.
      Onload of Body i m using following code..
      setTimeout(scrollTo, 0, 0, 1);
      Please suggest me…

      Reply
        • Author: RaphaelDDL
        • Posted on: 2012/01/02
        • At: 19:39

        shouldnt be an anonymous function?

        Like setTimeout(function(){scrollTo(0,0);},1);

      • Author: wuzehai
      • Posted on: 2012/02/01
      • At: 12:20

      onBeforeScrollStart: function (e) {if(e.target.tagName!=’INPUT’){e.preventDefault();} },

      Reply
    • Author: Daniel
    • Posted on: 2011/10/23
    • At: 21:51

    This is really great, great script and thanks Matteo for that, but unfortunately i can’t use it on my new project and i am really, really pist off and angy cause of that. This is rocket science for shitty, fuckin IE, aah, should be forbiden by law. People stop using it!

    Reply
      • Author: Marcus
      • Posted on: 2011/10/28
      • At: 09:14

      I’m using it with IE without any problems.
      Nested 2 iscroll for 2 different directions.

      Only browser that don’t work very well is Opera, since the lack of HW acceleration. Even O12b has HW acc but it doesn’t work satisifying.

      Reply
        • Author: Aaron
        • Posted on: 2011/11/06
        • At: 08:27

        ANy hacks needed for the js or the markup in calling the script to avoid undefined errors, and object not supported?

    • Author: mtz
    • Posted on: 2011/10/25
    • At: 12:55

    looks good! But i also likes to know how i can preserve native page scrolling in vertical direction when the user tabs in the iscroll area.

    Reply
      • Author: Gordon
      • Posted on: 2011/10/30
      • At: 22:46

      Second this.

      Reply
        • Author: Tom
        • Posted on: 2011/11/01
        • At: 16:59

        Third this.

        • Author: Georgi
        • Posted on: 2011/11/15
        • At: 00:27

        The solution you are looking for is on page 6 of these comments, posted by a user called “Gordon”. :)

      • Author: Nick B
      • Posted on: 2011/11/14
      • At: 17:29

      A clever chap called freshesyeball has a fix for this:
      https://groups.google.com/forum/#!msg/iscroll/qusOnwII_dU/yct_D8lGhTAJ

      Reply
    • Author: James
    • Posted on: 2011/11/01
    • At: 17:46

    Hi,

    I used your example above on a client’s website to try and fix a scrollbar bug we had with the site when viewing on an iPad. In Internet Explorer 9 it caused the entire site (bar the main nav and footer links to disappear after 3 seconds. Very strange. I have since removed this script from the site and suggest its something you look at.

    Reply
    • Author: Aaron Fransen
    • Posted on: 2011/11/02
    • At: 22:00

    Strange thing, and I noticed you say you have “form issues”, but when I have the iScroll moving an area, the form boxes inside it (ie. input type text and checkbox) do not respond, yet other click events do.

    Is this the problem you refer to?

    Reply
    • Author: Marcelo
    • Posted on: 2011/11/02
    • At: 22:34

    Hi, Im’ having strange issue using a vertical scroller with snap.
    On iPad iOS4, everything works perfect, but when a target to iOS5, the snapping which I’ve setup to ‘li’ doenst work. I pull down but the scroll back where it started.

    Reply
    • Author: Thomas
    • Posted on: 2011/11/12
    • At: 15:54

    iScroll is just great! And I mean the entire experience, the script, the quality of the code, the license and the description on your website. Many many thanks!

    Reply
    • Author: Mike
    • Posted on: 2011/11/13
    • At: 10:59

    Thank you for this, this is one of the most useful scripts a mobile web developer can use, without having to download a huge mobile library!

    Reply
    • Author: Kareem
    • Posted on: 2011/11/16
    • At: 05:31

    This is a great library. I use it for just about every project.

    Is there something in the API that would allow a user to scrollTo next/previous pages based upon the current position and the snap attribute?

    Reply
      • Author: Kareem
      • Posted on: 2011/11/16
      • At: 22:15

      I found it.
      just replace x / y with ‘prev’ / ‘next’
      scrollToPage(x,y,time);

      Although this will skip a partially shown element within the scroller.

      Reply
    • Author: lyonnel
    • Posted on: 2011/11/16
    • At: 11:53

    Thanks for iscroll. It’s a wonderful script.

    I have a “noob” question: What is the best way to disable/enable the scroll (touch or drag mouse) in javascript ?
    example: a carousel of images. When I click on an Image, it’s replaced by a video. If I don’t disable scroll, I can’t use the videoplayer (If I try to drag the video slider it will scroll the carousel instead)

    Reply
      • Author: lyonnel
      • Posted on: 2011/11/16
      • At: 12:04

      oops… I didn’t see enable and disable functions ^^

      Reply
        • Author: lyonnel
        • Posted on: 2011/11/16
        • At: 12:07

        edit: still have a problem : with iscroll disabled, i still cannot use player interface (it’s a youtube iframe)

    • Author: Kev
    • Posted on: 2011/11/16
    • At: 20:36

    Would it possible to have a div tag that would allow for the text to be highlighted by a mouse dragging over it with the left mouse button down. As of now, you never can select the text. Let me know if you need a little *help* for your troubles ;)

    Reply
    • Author: guru
    • Posted on: 2011/11/18
    • At: 06:43

    when implementing iscroll3.7 i had problem with input field not editable. i fixed that issue. now when the input field is focused and the keypad in iphone opens up once i’m done entering the value in the textbox and press ‘done’ in the keyboard, Key board disappears but the header is not resetted to the same place.
    Im using jquery wrapper and jquery mobile along with the iscroll. Can some one help me out with this issue ?

    Reply
    • Author: Vhs
    • Posted on: 2011/11/23
    • At: 02:02

    Any progress on the OnScroll event not being triggered? any workarounds?

    Reply
    • Author: Ho
    • Posted on: 2011/11/23
    • At: 17:04

    Hey there,
    I use iscroll as a pager with page-indexbuttons:

    (onclick=”contentPager.scrollToPage(0, 0);return false)

    But I have an issue: If I click on another Pageindex BEFORE the current scrolling stopped, the pageposition freezes anywhere in the middle. Is there a setting to prevent this?

    THX

    Reply
      • Author: Ho
      • Posted on: 2011/11/24
      • At: 08:53

      ok, I found the answer myself: I now use the isReady() method to ask if its true when clicking on a pagebutton

      Reply
  • Run nice on galaxy S2 but very slow on iPad and iPhone 4/iPod running iOS 5 …
    Can’t give you access to the site it’s a b2b shop …

    Reply
    • Author: Josh
    • Posted on: 2011/11/24
    • At: 18:47

    Love this project – so brilliant for beginner web app developers like me.

    Couple of questions if yourself or people have time to answer?

    Is it possible to nest a horizontal scroller (like your snap to element example), with-in a vertical scroller? If so you do you know of any examples where I can look at the script and source.

    If its impossible, can you let me know thanks – other wise I may be forever trying lol

    Reply
    • Author: lyonnel
    • Posted on: 2011/11/28
    • At: 17:13

    Hi.
    Is there an easy way to do “infinite” (looping if you prefer) scroll with iscroll ?

    Reply
    • have a look at swipeview http://cubiq.org/swipeview

      Reply
        • Author: lyonnel
        • Posted on: 2011/11/29
        • At: 11:02

        Thanks.
        Swipeview Demo looks awesome on my mobile but doesn’t work on my computer (no scroll at all). I know Swipeview and iScroll are made for mobile but iScroll is so great on mobiles and computers (except on IE) that I used it for both.

  • Infinite scrolling.
    Iscroll has more more power then swipe view.
    If you want to achieve infinite scrolling:
    1) Create a method called immediateScrollToPage and copy scrollToPage Changing the last line with: that.scrollTo(x, y, 0);

    Then
    onScrollEnd: function () {
    if (doNothing) doNothing=false;
    else {
    if (myScroll.currPageX>1) {
    $listLi = $(“#thelist li”);
    $listLi.last().after($listLi.first());
    //IMMEDIATE SCROLL IS A CUSTOM EDITING OF ISCROLL LIBRARY TO AVOID THE 0 PROBLEM (if you put 0 is evaluate as false and default time of 400ms is fired)
    myScroll.immediateScrollToPage(“prev”,0,0);
    } else {
    $listLi = $(“#thelist li”);
    $listLi.first().before($listLi.last());
    myScroll.immediateScrollToPage(“next”,0,0);
    }
    doNothing= true;
    }
    }

    On load scroll to page2 at first if you want to go left immediatly.

    Thanks Matteo for your plugin.

    Reply
      • Author: lyonnel
      • Posted on: 2011/12/02
      • At: 11:08

      Thanks.
      Your message helped me a lot.

      Reply
    • Author: @bhitalks
    • Posted on: 2011/12/01
    • At: 17:05

    Just came to know about cubiq, and guess what from where???

    From the Microsoft’s Windows Phone Demo for iPhone!!!

    http://aka.ms/wpdemo

    And am blown away by the quality of scripting here at cubiq. Great scripts and great effort!

    Reply
  • Microsoft is a software company. They have phone code. They made a mobile demo.
    Windows Phone.

    http://m.microsoft.com/windowsphone/en-us/demo/index.html
    Its js library contains a nearly intact minified iScroll 4.

    Reply
    • Author: kim
    • Posted on: 2011/12/05
    • At: 04:54

    hScroll and vScroll can use same time ?

    Reply
    • Author: Charles
    • Posted on: 2011/12/06
    • At: 01:47

    I’ve been stuck on this all day. How do I get a page that has a wrapper that is 300px tall to scroll properly on a blackberry that with a viewing screen 150px tall?

    Reply
      • Author: Charles
      • Posted on: 2011/12/06
      • At: 02:32

      “blackberry” may have been misleading.

      consider any mobile device. set a wrapper to ~200px taller than the device’s display and the width to 100%. how do you touch and drag to get the page to scroll down?

      Reply
        • Author: Astrid
        • Posted on: 2011/12/19
        • At: 10:46

        I have the same problem (with height and width) . Have you found a solution already?

    • Author: Wilton
    • Posted on: 2011/12/06
    • At: 08:09

    When I use iScroll4 in my app, I’ve found that if the scroll area has a tag (hyperlink) in it. It will bounce back after the scroll down. It will be perfect if I remove the a tag. Is it a known issue?

    Reply
      • Author: Pieter
      • Posted on: 2012/01/16
      • At: 14:43

      I’ve the same problem. A long list with DIV’s (formatted as a table). Per row DIV I have a onClick(). After scrolling down it will bounce back to it’s original state.
      I have the impression that the content (long list) is available, but iScroll doesn’t have it’s correct height (say zero). So it jumps back to it’s minimal display (coordinates 0.0)

      Reply
    • Author: Francisco Lopez Lecube
    • Posted on: 2011/12/07
    • At: 02:11

    Hi!! Awsome tool !! I love it. Only one question: I have a full screen carousel, and a small scrolling div in the wraper…. The problem is when i try to vertically scroll the div and the finger slides just a little bit horizontally, the carousel will trigger the page swich.
    Is posible to add some event ontouchstart on the div to avoid the carousel movement ?

    Thank you !!!

    Reply
      • Author: Francisco Lopez Lecube
      • Posted on: 2011/12/07
      • At: 03:32

      I found the solution, i added two events to the scrolling div to disable the carousel…… ontouchstart=”myScroll.disable()” ontouchend=”myScroll.enable()”

      Reply
    • Author: putto72
    • Posted on: 2011/12/08
    • At: 22:23

    Great script.. I wish it worked even on the new Windows Phone 7.5 (Mango), it would cover practically all mobile phones.

    Reply
    • as far as I know, Mango doesn’t support mouse/touch-move events

      Reply
        • Author: putto72
        • Posted on: 2011/12/13
        • At: 14:40

        I had a Lumia 800 for 5 minutes, and tried a mobile website I am working on (which includes iScroll 4). I was told that the engine of the mobile browser was that of IE 9 desktop, but obviously this is not true.. There are no alternatives, apart from displaying the old scrollbar when this new browser is (somehow) detected?

    • Author: Moo
    • Posted on: 2011/12/09
    • At: 09:17

    I have a list view which initially shows 20 items on scrolling down to bottom of the list i need to fetch the next set of 20 items and display them via AJAX. How this can be achieved using iscroll ?

    Reply
      • Author: Juan Francisco
      • Posted on: 2011/12/20
      • At: 17:58

      You can override onScrollMove method in the constructor and add the following code:

      if (this.y <= (this.maxScrollY – 5)) {
      $(document).trigger('endoflist');
      }

      You can bind this event to a method which it do de AJAX call.

      Reply
    • Author: re
    • Posted on: 2011/12/12
    • At: 01:32

    is it possible to implement pull to refresh horizontally?

    Reply
    • Author: Rafa
    • Posted on: 2011/12/12
    • At: 16:26

    I have a WebApp using JQtouch. Like other framework for making WebApp, each diferent view is really a DIV that becames visible = true while the other DIV views became visible = false.
    My WebApp use many views. Some of this views are lists using Iscroll 4.
    Currently I use only a global variable for iscroll object in the HTML page named myScroll.
    Each time a view becomes visible and I must use iscroll I use myScroll.destroy() first and then I crete new iscroll myScroll = new iScroll(obj) for the visible view.
    Actually this is working very well (even if the user rotate the device or the list has changed its items, the next visible view refresh its scroll) but do you think I must create a Iscroll for each view?
    If I had 30 view what method would be the best for the device in terms of performance and resource.

    If I must use a Iscroll object per view, which method do I use for handling scrolls refresh only in the iscroll of the visible view?

    Sorry my bad English.

    Thank you very much in advance and for all this work.

    Reply
    • Author: Kumar Amit Ranjan
    • Posted on: 2011/12/12
    • At: 17:38

    Great Library.

    Reply
    • Author: CodeSix
    • Posted on: 2011/12/13
    • At: 19:58

    I tried using iScroll 3 or 4 with iuiscroll, they finally worked together after some tweaks, however when scrolling with an amount of floating sqaure 20×20 thumbnail anchors (around 20) along with some other LI’s, the scrolling become choppy and the page is impossible to browse on both iPhone 3&4 (scrolling works fine on PC Safari), tried adding useTranstition but no help, is there a way to improve the performance or just my fault?

    Reply
    • Author: lyonnel
    • Posted on: 2011/12/14
    • At: 17:39

    Hello,
    I made an horizontal carousel with automatic scroll and with snap to each page. It works fine but I notice a bug : when I move the mouse vertically in over and out of the scroll zone, the scroll accelerate and, on firefox (not safari/chrome), stop without snapping to the page.
    I first though it was because of my code but I finally noticed the bug is already in the iscroll carousel demo (you must move the mouse very quickly after clicking on the prev or next button).

    have someone a solution to this bad snapping bug on firefox ? (acceleration is not a problem)

    Reply
    • Author: Niclas
    • Posted on: 2011/12/16
    • At: 11:35

    At first I couldn’t click any input fields when surfing my iScroll page in iPhone/Safari, and then I noticed this code:

    myScroll = new iScroll('iscroll_wrapper', {
    useTransform: false,
    onBeforeScrollStart: function (e) {
    var target = e.target;
    while (target.nodeType != 1) target = target.parentNode;

    if (target.tagName != 'SELECT' && target.tagName != 'INPUT' && target.tagName != 'TEXTAREA')
    e.preventDefault();
    }
    });

    After using it, the scrolling seemed slower/laggy, but the input fields worked. Then I removed the code again, and the input fields still work.

    So I cleaned the cache of Safari, and revisited the page, without the code above. The input fields still works.

    What is going on? Is Safari caching javascript local on a page? Seems very weird…

    Reply
      • Author: Niclas
      • Posted on: 2011/12/16
      • At: 11:39

      Ok, my bad. When disabling the input code, I disabled the entire iScroll. So it’s probably nothing.

      But another problem I have is that the tap highlight is not visible inside the iScroll. Is there a reason for this, and can it be fixed?

      I noticed I can use the :active on links, to change the color, but it’s usually hidden under my fat finger. :)

      Would be great with a FAQ on iScroll with these kinds of questions. Thanks anyhow for a great script, just gotta make it work :P

      Reply
    • Author: Francisco Lopez Lecube
    • Posted on: 2011/12/19
    • At: 19:57

    Hi !! is there any way to change the carousel sensitivity ??? I have a full screen carousel but with a small finger slide it changes the div. THanks !!

    Reply
    • yes, increase the snapThreshold option

      Reply
    • Author: Marco
    • Posted on: 2011/12/20
    • At: 10:15

    Hi!
    How can I lock the last item menu so that it can no longer scroll the menu to the left and the background is not shown

    Reply
    • Author: xusheng
    • Posted on: 2011/12/21
    • At: 08:16

    This is a good program, I have a question, if my fingers up and down, I do not want to trigger the action, so that the external scroll bar moves up and down with the fingers, when I slide around when he was operating

    Reply
    • Author: Jack
    • Posted on: 2011/12/22
    • At: 10:16

    I want to release the left slide and right slide for ipad.In other words, I just want to let it detect the mouse slide-up and slide-down.Can you help me?Thank you.

    Reply
    • Author: 熠熠
    • Posted on: 2011/12/29
    • At: 07:59

    i’m uesing this script in my first website for ipad owners.This is a good program!

    Reply
    • Author: Alex
    • Posted on: 2012/01/02
    • At: 12:13

    Thanks for sharing this awesome piece of code with the world. While playing around with the code and an iPad. I came across a bug that might already be known but I couldnt find it on either github or here:

    I was making an webapp for iPad with iScroll but the scrollable DIV had CSS display:none;. With a simple javascript toggle I could show/hide the iScroll DIV but the above CSS settings would disable iScroll. I dont have a code sample but it shouldnt be hard to reproduce this bug. If the DIV didnt have the display:none; at pagerendering and was hidden/shown at a later stage (by toggle) it would still work perfectly.

    Reply

/Leave a reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>