This text link: http://www.cnblogs.com/duanhuajian/archive/2013/04/08/3008323.html
Overview Iscroll 4 This version completely rewrites the original code of the Iscroll framework. This project was created entirely because mobile webkit browsers (such as Iphone,ipad,android, which are widely used on these systems) provide a localized way to slide the content of an element that limits height and width. Unfortunately, in this case, all Web application pages cannot contain a position:absolute header, footer, or an intermediate area where content can be scrolled. However, the latest revision of the Android system has been able to support this feature (although the strength of the support is not particularly good), Apple seems reluctant to apply the One-finger slide event to the DIV element. In addition to the features of previous versions of Iscroll, the Iscroll 4 also includes the following features: (1) Scaling (Pinch/zoom) (2) Pull refresh (pulling Up/down to refresh) (3) Speed and performance boost (4) Precision snap element Vegetarian (5) Custom scroll bar tip: Iscroll 4 is not a simple alternative to Iscroll 3, and the API documentation is different. While considering that this version is in beta, some APIs may change slightly. Usage Guide In this document you will find a number of examples to teach you how to quickly get started with the Iscroll script library. It may be a little boring to see the demo small example and read this document carefully, but this article is the essence of the Iscroll script library. Iscroll needs to initialize the elements to be scrolled, and does not limit the number of elements in a page that use Iscroll (your hardware configuration is not considered here). The type and length of content in the scrolling element will, to some extent, affect the number of elements that can be used concurrently in the Iscroll script library. When using the Iscroll script library, the structure of the DOM tree is simple enough to remove unnecessary tags and try to avoid excessive tag nesting. The optimal structure for using Iscroll is as follows: <div id= "wrapper" > <ul> <li></li> ... </ul></div> in this small example, the UL tag will be scrolled. Iscroll Be sure to contact the wrapper outside the scrolling content to produce an effect. "Caveats": only the first child element in the wrapper can be scrolled, if you want more elements toTo scroll, then you can try this: copy code <div id= "wrapper" > <div id= "scroller" > <ul> <li></li> ... </ul> <ul> <li></li> ... </ul> </div></div> copy code in this example, scroller This element can be scrolled, even if it contains two UL elements iscroll must be instantiated before the call, you can instantiate the Iscroll in the following cases: (1) Use the Ondomcontentloaded event to scroll for scrolling content that contains only text, pictures, And all the pictures have fixed size copy code <script src= "Iscroll.js" ></script> <script> var myscroll; function loaded () {myscroll=new iscroll ("wrapper"); } window.addeventlistener ("domcontentloaded", Loaded,false); </script> Copy Code Note: Myscroll This variable is global, so you can call it anywhere (2) Use the OnLoad event to implement scrolling because the Domcontentloaded event is loaded after the DOM structure is , you may not be able to determine the length and width of the scrolling area before elements such as pictures are loaded, which can be accomplished using the OnLoad event. Copy code <script src= "Iscroll.JS "><script> <script> var myscroll; function loaded () {SetTimeout (function () {myscroll=new iscroll ("wrapper"); },100); } window.addeventlistener ("Load", loaded,false); </script> copy code in this case, Iscroll will be initialized after the page resource (including the picture) has finished loading 100ms, which should be a safe way to call Iscroll. (3) Inline initialization is called when the page is loaded into JS, this method is not recommended, but many JavaScript Daniel are in this way, I have no reason to disagree? Copy code <script src= "Iscroll.js" ></script> <div id= "wrapper" > <ul> <li></li> ... </ul> </div> <script> var myscroll=new iscroll ("wrapper"); </script> Copy Code However, it is recommended that you use some of the framework's ready methods to safely invoke Iscroll (such as ready () in jquery). The parameters passed in the Iscroll iscroll.The second parameter allows you to customize some of the content, such as the following code: <script> var myscroll=new iscroll ("wrapper", {hscrollbar:false, Vscrol Lbar:false}); </script> The second parameter is usually an object, as in the example above, the scroll bar is not displayed. Common parameters are as follows: HScroll false Disables horizontal scrolling true horizontal scrolling defaults to true VScroll false fine Vertical scrolling true Vertical scroll defaults to True HScrollbar false Hide horizontal scroll bar VScrollBar false Hide Vertical Scroll bars in the direction Fixedscrollbar on iOS systems, when an element is dragged beyond the bounds of scroller, the scrollbar shrinks and set to true to prevent the scrollbar from exceeding The visible area of the scroller. The default is true on Android, False Fadescrollbar on iOS specifies that scrollbars are hidden when no fade effect is hidescrollbar when no user interaction Hide scroll bar default is true bounce enable or disable bounce of boundary, default is true momentum enable or disable inertia, default is true, this parameter is in the resource you want to save is very useful lockdirection false to cancel the lock of the drag direction, true to drag only in one Direction (Up/down or Left/right) the implementation of various effects rolling refresh ' pull to Refres H ' demo since Twitter and some of Apple's localization apps have come to this effect,This effect becomes very popular. You can see the first glimpse here. In the latest version, the author divides the "Pull to refresh" section as an additional plugin for iscroll. You can click here to see how pull-to-refresh works. All you have to do is customize the Pulldownaction () method. You may need an AJAX to load the new content, but once the DOM tree has changed, remember to call the Refresh method. It should be remembered that in the example we added a delay of 1 seconds to simulate the delay effect of the network. Of course, if you do not want to use this delay, then the SetTimeout method to remove the line. Zoom (pinch/zoom) ' Pull to refresh ' demo we have to face the fact that there is nothing new about light rolling. This is why in this version of Iscroll 4 we allow you to zoom in and out. To do this, you only need to set the magnification parameter zoom to TRUE to zoom in and out using gestures. You can look here. The ability to double-click Zoom in and zoom Out is also supported in Iscroll 4. To use the zoom feature, you need at least the following configuration: Var myscroll =new iscroll ("wrapper", {zoom:true}); If you want to customize the zoom function in depth, you can use some of the following options: zoommax Specifies the maximum number of magnification allowed, default is 4 "Note": If you want the picture to scale well, put them in the hardware's composition layer. In layman's terms, this is done using-webkit-transform:translate3d (0,0,0) on all the IMG elements that need to be scaled, and, most importantly, hardware acceleration can take up a lot of resources, so use it sparingly, or your app might crash. The Capture Element (snap and Snap to Element) ' Carousel ' demo snap function is to determine whether the element is sliding to the specified position. With this effect you can make fancy marquee effects. The plug-in automatically parses the same label or element of the same size in the scrolling area as a snap object, or it can specify the object to be captured by the Var myscroll=new iscroll ("wrapper", {s Nap:true, Momentum:false, Hscrollbar:false, Vscrollbar:false }); You can set the snap parameter to a specified label to set the snapping object. such as capturing the Li tag. var myscroll=new iscroll ("wrapper", {snap: "Li", Momentum:false, Hscrollbar:false, vscrollbar:false}); In this example scroller can snap to the top left corner of the scroll area of the LI element custom scrollbar (named scrollbars) in Iscroll 4, a series of CSS can be used to customize the rendering of the scroll bar. You can add a class parameter to the scroll bar as follows: Var myscroll=new iscroll ("wrapper", {scrollbarclass: "Myscrollbar"}); A reminder is that the scrollbar is composed of two elements: a container and a monitor. The container is the same height as the wrapper, while the display represents the scroll bar itself. The HTML structure of the scroll bar is as follows: Copy code <div class= "Myscrollbarv" > <div></div > </div>. 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 do 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); The common method of copying code: (1) Refresh should call this method when the DOM tree changes eg:settimeout (function () {Myscroll.refresh ( ); }, 0); (2) Iscroll also provides Scrollto, Scrolltoelement, and scrolltopage three methods that allow you to control the scrolling effect via JavaScript. ScrollTo (x, Y, Time, relative): The position of the content scrollbar X/y within the specified time period. such as Myscroll.scrollto (0,-100, 200) the y-axis scrolls down 100 pixels within 200 milliseconds. Myscroll.scrollto (0, ten, Max, true) can achieve the effect of scrolling up to 10 pixels in the y-axis relative to the current position within 200 milliseconds. Scrolltoelement (element, time): Scrolls to the specified element within the specified period. such as Myscroll.scrolltoelement (' Li:nth-child (10) ', 100) scrolls to the position of the 10th Li element within 100 milliseconds. The 1th parameter can be used to filter elements using selectors in CSS3. Snaptopage (PageX, Pagey, Time): Scrolls from 1th page to 2nd page (0 for 1th page and 1 for 2nd page) within 200 milliseconds. This function can be called when the snap function is used. (3) DeTroy () completely eliminate the myscroll and its occupied memory space Eg:myscroll.destroy (); Myscroll = Null;iscroll Development Direction form Field Support scaling optimization better desktop browser compatibility Onscrol event optimization Add a hash value change automatically refresh after DOM changes
Iscroll.js Usage Reference