I am new to the front-end, and I would like to share the implementation process of the touch screen carousel on the mobile phone. The general functions are as follows:
Supports circular sliding
The width can be set arbitrarily and does not need to be the same width as the screen
The page can be scrolled vertically
The switching of callback listening elements can be set
Pure js, without any third-party library
Assumption of child elements The
width of .item
is 375px, use absolute positioning to place all child elements within the parent element
Place the parent element .carousel## The
width is set to 375px, which is the same width as the child element
.item
.carousel Touch events:
touchstart,
touchmove,
touchend
clientX)
transform attribute of the current element to
translate3d(0px, 0px, 0px) and change
z-indexAttribute+1
transform attribute of the next child element to
translate3d(375px, 0px, 0px), and
z-indexAttribute+1
transform attribute of the previous child element to
translate3d(-375px, 0px, 0px), and set the
z-index attribute +1
z-index attribute of all other child elements to Default value
When moving, the transform attribute of the child element .item is set, not the parent element.carousel
## Implementation Steps
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 |
|
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 |
|
After you have the linked list, create a linked list instance, add the child elements to the linked list, and set some initial states
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Bind touch events
1 2 3 4 5 6 7 8 9 10 11 |
|
touchmove event
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
touchend event
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 |
|
Carousel library
, next()
methods are very simple to use:
1 2 3 4 5 6 7 8 9 |
|
Copy after login
This library can be downloaded from githubReference
H5 single page gesture sliding screen switching principle
good night!
【Related recommendations】
1.
Free h5 online video tutorialHTML5 full version manualphp.cn original html5 video tutorialThe above is the detailed content of An example tutorial on implementing a carousel (touch screen version) using H5. For more information, please follow other related articles on the PHP Chinese website!
Related labels:
Previous article:Share a wave effect code made using HTML5
Next article:An example tutorial of using H5 to create a countdown demo
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
Latest Articles by Author
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
-
1970-01-01 08:00:00
Latest Issues
-
2025-03-18 14:18:31
-
2025-03-18 14:17:34
-
2025-03-18 14:16:27
-
2025-03-18 14:07:32
-
2025-03-18 14:06:34
Related Topics
More>
-
what is h5
-
How to implement h5 to slide up and load the next page on the web side
-
What is the shortcut key for switching users?
-
Drawing software
-
Recommended hard drive detection tools
-
How to open jar files
-
How to delete WeChat emoticons
-
What is the statement to delete a table in sql
-
How to solve 400 bad request
Popular Recommendations
Popular Tutorials
More>
-
-
-
JAVA Beginner's Video Tutorial
2679904
-
-
Latest Downloads
More>
-
-
-
-
-
-
-
-