What is iScroll? Detailed explanation of iScroll usage examples
The creation of iScroll:
The creation of iScroll is entirely due to the mobile webkit browser, such as on iPhone and Android mobile devices.
How to use iScroll:
The principle of iScroll is that there is an overflow hidden (overflow:hidden;) DOM in the outer layer, and then the first DOM structure in this area will be instantiated, and its wrapper The content can be scrolled vertically or horizontally, so when using iScroll, the scrolling elements should be as simple as possible, reduce the number of DOMs, and reduce nesting, because the more complex the DOM structure is, the more difficult it will be for iScroll to run, which may cause Some nodes show abnormal behavior. Therefore, the recommended DOM structure is as follows:
<p id="wrapper">//overflow:hidden; <ul> //只有第一个DOM结构(ul)被实例化,这个DOM可以纵向或者横向的滚动, //多出的内容会被wrapper的样式hidden。 <li>1</li> <li>2</li> <li>3</li> </ul> </p>
Note: Once again, only the first child element (ul) in the wrapper can be instantiated and scrolled, and To achieve scrolling, it must be combined with the outer DOM (wrapper).
What if there are multiple uls in the wrapper? It's very simple. Remember that sentence, only the first child element (ul) in the wrapper can be instantiated and scrolled:
<p id="wrapper">//overflow:hidden; <p id="first"> //只有第一个DOM结构(ul)被实例化,这个DOM可以纵向或者横向的滚动, //多出的内容会被wrapper的样式hidden <ul> <li>1</li> <li>2</li> <li>3</li> </ul> <ul> <li>4</li> <li>5</li> <li>6</li> </ul> </p> </p>
See, only the first will be instantiated. Note: You don’t need to write the ID of the first DOM structure here (first). I just wrote an ID to facilitate everyone’s identification, but the outermost ID (wrapper) must be written because it is needed when JS is instantiated. Fill in this ID:
var myScroll = new iScroll("wrapper");
How should iScroll be instantiated:
Now that instantiation is mentioned, when should we instantiate it? change? It is said that there are many methods of instantiation, but I have never used them. I will only say one:
(1) Load iscroll.js and uw3c of the current page at the bottom of the HTML (uw3c.html) page (after body and before html) .js, this ensures that the HTML DOM structure can be loaded.
(2) Instantiate iScroll before JS inserts the page DOM structure and data, that is, instantiate it at the beginning of JS, because JS may be used to insert DOM or data later, so as to ensure that iScroll is inserted before data is inserted. Already instantiated.
HTML://HTML structure
<html > <body> ...code... </body> //插入iscroll.js文件 <script type="text/javascript" src="js/iscroll.js" > </script > //插入本页面JS文件 <script type="text/javascript" src="js/uw3c.js" > </script > </html>
JS://JS file content
var myscroll; function iscroll(data){ //实例化iScroll myscroll=new iScroll("wrapper"); pageData(data); } function pageData(obj){ $("body").html(obj); myscroll.refresh();//当DOM结构发生变化的时候,需要刷新iScroll } iscroll("<p>pagedata</p>");
Parameters in iScroll:
When instantiating iScroll, you can pass in two parameters. The first parameter is the ID of the instantiated outer DOM, and the second parameter The parameter is the object of the iScroll execution method:
var myscroll=new iScroll("wrapper",{hScrollbar:false}); 或者 var opts = { vScroll:false,//禁止垂直滚动 snap:true,//执行传送带效果 hScrollbar:false//隐藏水平方向上的滚动条 }; var myscroll = new iScroll("wrapper",opts);
The content of the second parameter is as follows. This parameter will control the effect of iScroll:
hScroll false 禁止横向滚动 true横向滚动 默认为true vScroll false 禁止垂直滚动 true垂直滚动 默认为true hScrollbar false隐藏水平方向上的滚动条 vScrollbar false 隐藏垂直方向上的滚动条 fadeScrollbar false 指定在无渐隐效果时隐藏滚动条 hideScrollbar 在没有用户交互时隐藏滚动条 默认为true bounce 启用或禁用边界的反弹,默认为true momentum 启用或禁用惯性,默认为true,此参数在你想要保存资源的时候非常有用 lockDirection false取消拖动方向的锁定,true拖动只能在一个方向上(up/down 或者left/right)
Methods in iScroll:
Of course, in the second parameter, there are also some methods that can be executed:
(1)scrollTo(x, y, time, relative) method: pass in 4 parameters: X-axis scrolling distance, Y-axis scrolling distance, effect time, whether it is relative to the current position. So for example:
//在200毫秒的时间内,Y轴向上滚动100像素; uw3c.scrollTo(0, -100, 200) //在200毫秒的时间内,相对于当前位置,X轴向左滚动100像素; uw3c.scrollTo(-100, 0, 200, true)
(2)refresh() method: After the DOM structure changes, iScroll needs to be refreshed, otherwise the scrolling plug-in will be instantiated inaccurately :
uw3c.refresh();//刷新iScroll
(3) onPosChange, is there a method that can return the change of position? You can check if there is an onPosChange method in the iScroll you are using:
onPosChange:function(x,y){ if(y < -200){ //如果Y周向上滚动200像素,$("#uw3c")就显示,否则就隐藏。 $("#uw3c").show(); }else{ $("#uw3c").hide(); } }
(4) onScrollEnd: event executed when the scroll ends. If you want to When you touch an event, this method will be useful:
//滚动结束后,执行的方法,滚动后会出现提示框alert("phpcn") onScrollEnd:function(){ alert("phpcn"); }
(5) onRefresh: After the DOM structure changes, iScroll needs to be refreshed, otherwise The scrolling plug-in will be instantiated inaccurately, and onRefresh is the method that will be executed after iScroll is refreshed.
(6) onBeforeScrollStart: The time callback before starting scrolling. The default is to prevent the browser's default behavior.
(7) onScrollStart: callback to start scrolling.
(8)onBeforeScrollMove: Callback before content moves.
(9) onScrollMove: callback for content movement.
(10) onBeforeScrollEnd: Callback before the end of scrolling.
(11) onTouchEnd: Callback after the hand leaves the screen.
(12) onDestroy: callback to destroy the instance.
The above is the detailed content of What is iScroll? Detailed explanation of iScroll usage examples. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











ccsvchst.exe is a common process file that is part of the Symantec Endpoint Protection (SEP) software, and SEP is an endpoint protection solution developed by the well-known network security company Symantec. As part of the software, ccsvchst.exe is responsible for managing and monitoring SEP-related processes. First, let’s take a look at SymantecEndpointProtection(

Support Vector Machine (SVM) in Python is a powerful supervised learning algorithm that can be used to solve classification and regression problems. SVM performs well when dealing with high-dimensional data and non-linear problems, and is widely used in data mining, image classification, text classification, bioinformatics and other fields. In this article, we will introduce an example of using SVM for classification in Python. We will use the SVM model from the scikit-learn library

Dual-core browser is a browser software that integrates two different browser cores. The kernel is the core part of the browser, responsible for rendering web content and executing web scripts and other functions. Traditional browsers generally use only a single kernel, such as IE browser using Trident kernel, Chrome browser using WebKit/Blink kernel, Firefox browser using Gecko kernel, etc. The dual-core browser integrates two different cores into one browser, and users can freely switch between them as needed. The emergence of dual-core browsers

As the new generation of front-end frameworks continues to emerge, VUE3 is loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player. 1. Install VUE3 First, we need to install VUE3 locally. Open the command line tool and execute the following command: npminstallvue@next Then, create a new HTML file and introduce VUE3: <!doctypehtml>

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

VAE is a generative model, its full name is VariationalAutoencoder, which is translated into Chinese as variational autoencoder. It is an unsupervised learning algorithm that can be used to generate new data, such as images, audio, text, etc. Compared with ordinary autoencoders, VAEs are more flexible and powerful and can generate more complex and realistic data. Python is one of the most widely used programming languages and one of the main tools for deep learning. In Python, there are many excellent machine learning and deep

With the rapid development of the Internet, data has become one of the most important resources in today's information age. As a technology that automatically obtains and processes network data, web crawlers are attracting more and more attention and application. This article will introduce how to use PHP to develop a simple web crawler and realize the function of automatically obtaining network data. 1. Overview of Web Crawler Web crawler is a technology that automatically obtains and processes network resources. Its main working process is to simulate browser behavior, automatically access specified URL addresses and extract all information.

What is ALICE coin? ALICE coin is a digital cryptocurrency inspired by the English word "ALICE", which symbolizes the unique creativity and imagination of the creator. As a virtual currency based on blockchain technology, ALICE currency aims to provide users with a safe, convenient and privacy-protected transaction environment. Application of Blockchain Technology In order to achieve the recording and verification of transactions, ALICE currency uses blockchain technology. Blockchain is a distributed database that links transaction information together in chronological order to form an immutable chain. This technology greatly improves the security of transaction information, while also eliminating the need for trust in third-party institutions and reducing transaction costs. Due to the decentralized nature of blockchain, transaction participants can
