It’s been a while since my last post. I’ve been working on some projects that are quite time-consuming; that’s why I can’t (despite having 3 prototypes) work much longer on games for the one game a month challenge.
For one of my apps using Phonegap and JQuery Mobile, I needed a list with the “pull to refresh” fonctionnality. After somes searchs and tests, I ended up using the Jquery Mobile iscrollview widget, that works pretty well.
So here is a quick start for this feature.
First of all, what is this widget for ?
This widget is a JQueryMobile version of the iScroll widget.
According to the autor website :
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.
By the way, this plugin allows you to use a lot of features like :
- Pinch / Zoom
- Pull up/down to refresh
- Improved speed and momentum
- Snap to element
- Customizable scrollbars
The code
Assuming that you have a Phonegap project already initialized, you need to add to your main html file :
|
|
And a page like this :
|
|
The “list-view” inside the “data-iscroll” tag will now have the “pull to refresh” feature. If you need to do some actions (like refresh the content, …) you have to listen for some events :
|
|
Here is the complete list of events for the pull-to-refresh feature :
- iscroll_onpulldown
- iscroll_onpullup
- iscroll_onpulldownreset
- iscroll_onpulldownpulled
- iscroll_onpulldownloading
- iscroll_onpullupreset
- iscroll_onpulluppulled
- iscroll_onpulluploading
The event callbacks takes two arguments :
|
|
The event argument is a basic JQuery Event. The data argument has only one member : iscrollview, that is the reference to the iscrollview object that made the callback.
And after that, if you want to hide the top or bottom part, just refresh the componant :
|
|
Customization
You can also custom the pull label text. All these options has default values, but you can custom them all :
- pullDownResetText (default: “Pull down to refresh…”)
- pullDownPulledText (default: “Release to refresh…”)
- pullDownLoadingText (default: “Loading…”)
- pullUpResetText (default: “Pull up to refresh…”)
- pullUpPulledText (default: “Release to refresh…”)
- pullUpLoadingText (default: “Loading…”)
If you want to change those values from the html, just set the correct attribute :
|
|
For more informations, here is the place you want to go.