Home Web Front-end JS Tutorial Implement content scrolling effect based on iScroll

Implement content scrolling effect based on iScroll

May 26, 2018 pm 05:03 PM
content scroll

This article mainly introduces the content scrolling effect based on iScroll in detail, which has certain reference value. Interested friends can refer to it

1. Introduction to iScroll

iScroll is a scrolling control for web apps. It can simulate the scrolling list operation in native IOS applications, and can also implement functions such as zooming, pull-to-refresh, precise element capture, and customized scroll bars. The version used by the blogger here is iScroll4.25. The latest version is iScroll5. You can download it from the official website.
Official website address: http://iscrolljs.com/

2. How to use iScroll

1.iScroll usage structure

The optimal structure for using iScroll is generally as follows:

HTML:

1

2

3

4

5

6

7

8

9

10

11

12

<p id="wrapper">

  <p id="scroller">

   <ul>

    <li></li>

    ...

   </ul>

   <ul>

    <li></li>

    ...

   </ul>

  </p>

 </p>

Copy after login

Note: 1. iScroll must contact the wrapper outside the scrolling content to have an effect.
2. Only the first child element in the wrapper can be scrolled.

2. Instantiate iScroll

iScroll must be instantiated before calling, the instantiation code is as follows (add the following code in the head tag) :

1

2

3

4

5

6

7

8

<script src="iscroll.js"></script>

 <script>

  var myscroll;//myscroll是全局变量,可以任意地方调用

  function loaded(){

   myscroll = new iScroll("wrapper");

   }

  window.addEventListener("DOMContentLoaded",loaded,false);

 </script>

Copy after login

3. Rolling test example

HTML CSS:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">

<meta name="apple-mobile-web-app-capable" content="yes">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<script src="iscroll-4.2.5fix.js"></script><!--引入js包-->

<!--实例化iScroll-->

<script type="text/javascript">

 var myscroll;

 function loaded(){

 myscroll = new iScroll("wrapper");

 }

 window.addEventListener("DOMContentLoaded",loaded,false);

</script>

<!--CSS样式设置-->

#wrapper {

 position:absolute; z-index:1;

 top:45px; bottom:48px; left:0;

 width:100%;

 background:#aaa;

 overflow:auto;

}

 

#scroller {

 position:relative;

/* -webkit-touch-callout:none;*/

 -webkit-tap-highlight-color:rgba(0,0,0,0);

 

 float:left;

 width:100%;

 padding:0;

}

 

#scroller ul {

 position:relative;

 list-style:none;

 padding:0;

 margin:0;

 width:100%;

 text-align:left;

}

 

#scroller li {

 padding:0 10px;

 height:40px;

 line-height:40px;

 border-bottom:1px solid #ccc;

 border-top:1px solid #fff;

 background-color:#fafafa;

 font-size:14px;

}

 

#scroller li > a {

 display:block;

}

</style>

<title>滚动测试</title>

</head>

<body>

<p id="wrapper">

 <p id="scroller">

  <ul id="thelist">

   <li>Pretty row 1</li>

   <li id="aaa">Pretty row 2</li>

   <li>Pretty row 3</li>

   <li>Pretty row 4</li>

   <li>Pretty row 5</li>

   <li>Pretty row 6</li>

   <li>Pretty row 7</li>

   <li>Pretty row 8</li>

   <li>Pretty row 9</li>

   <li>Pretty row 10</li>

   <li>Pretty row 11</li>

   <li>Pretty row 12</li>

   <li>Pretty row 13</li>

   <li>Pretty row 14</li>

   <li>Pretty row 15</li>

   <li>Pretty row 16</li>

   <li>Pretty row 17</li>

   <li>Pretty row 18</li>

  </ul>

 </p>

</p>

</body>

</html>

Copy after login

4. Running effect


The blogger just started Learning, partial content scrolling is only the most basic function of iScroll. Next, bloggers will try to pull refresh and other functions.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Simple application based on Ajax form submission and background processing

Ajax is simple to upload pictures and preview them Implementation

Summary of file upload skills based on ajax html

# #

The above is the detailed content of Implement content scrolling effect based on iScroll. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to enable Sensitive Content Warning on iPhone and learn about its features How to enable Sensitive Content Warning on iPhone and learn about its features Sep 22, 2023 pm 12:41 PM

How to enable Sensitive Content Warning on iPhone and learn about its features

How to change the Microsoft Edge browser to open with 360 navigation - How to change the opening with 360 navigation How to change the Microsoft Edge browser to open with 360 navigation - How to change the opening with 360 navigation Mar 04, 2024 pm 01:50 PM

How to change the Microsoft Edge browser to open with 360 navigation - How to change the opening with 360 navigation

How to implement scrolling to a specified element position in JavaScript? How to implement scrolling to a specified element position in JavaScript? Oct 22, 2023 am 08:12 AM

How to implement scrolling to a specified element position in JavaScript?

Monitor iframe scrolling behavior Monitor iframe scrolling behavior Feb 18, 2024 pm 08:40 PM

Monitor iframe scrolling behavior

HTML, CSS, and jQuery: Make an auto-scrolling bulletin board HTML, CSS, and jQuery: Make an auto-scrolling bulletin board Oct 27, 2023 pm 06:31 PM

HTML, CSS, and jQuery: Make an auto-scrolling bulletin board

Where to set the download button in Microsoft Edge - How to set the download button in Microsoft Edge Where to set the download button in Microsoft Edge - How to set the download button in Microsoft Edge Mar 06, 2024 am 11:49 AM

Where to set the download button in Microsoft Edge - How to set the download button in Microsoft Edge

How to set up Cheat Engine in Chinese? Cheat Engine setting Chinese method How to set up Cheat Engine in Chinese? Cheat Engine setting Chinese method Mar 13, 2024 pm 04:49 PM

How to set up Cheat Engine in Chinese? Cheat Engine setting Chinese method

How to use JavaScript to achieve the infinite scroll effect of automatically loading when scrolling to the bottom of the page? How to use JavaScript to achieve the infinite scroll effect of automatically loading when scrolling to the bottom of the page? Oct 27, 2023 pm 06:30 PM

How to use JavaScript to achieve the infinite scroll effect of automatically loading when scrolling to the bottom of the page?

See all articles