当前位置:网站首页>Summer Challenge harmonyos - slider slider for custom components
Summer Challenge harmonyos - slider slider for custom components
2022-07-25 07:36:00 【51CTO】
author : Fan lele
This article is participating in the starlight project 3.0– Summer Challenge
Preface
Studying recently HarmonyOS Develop relevant knowledge , Useful in the project development process slider Slider as , This paper mainly combines with HarmonyOS Relevant components on the official website and general API, Achieve one slider Slider as .
Effect demonstration

Realization principle
1. The trigger condition
be based on HarmonyOS General events touchstart and touchmove, Trigger when your finger just touches the screen 、 The event is triggered when the finger moves after touching the screen ;
2. Realization slider Slider effect
adopt touches Set of attributes when touching an event , Return the information array of touch points on the screen , Get localX Horizontal distance from the upper left corner of the touched component , Dynamically calculate the width of sub elements to achieve slider Slider effect .
3. Achieve percentage display
adopt HarmonyOS Common methods getBoundingClientRect() Get the width of the element itself ; Remove the width of the element itself by sliding distance , To achieve the percentage of slider movement ;
The official used API
Common methods
getBoundingClientRect()
Get the size of the element and its position relative to the window .
| attribute | type | describe |
|---|---|---|
| width | number | The width of this element . |
| height | number | The height of this element . |
| left | number | The offset of the left edge of the element from the window . |
| top | number | The offset of the upper boundary of this element from the window . |
General events
| name | Parameters | describe | Whether it supports bubbling |
|---|---|---|---|
| touchstart | TouchEvent | This event is triggered when the finger just touches the screen . | yes 5+ |
| touchmove | TouchEvent | This event is triggered when the finger moves after touching the screen . | yes 5+ |
| attribute | type | explain |
|---|---|---|
| touches | Array<TouchInfo> | Set of attributes when touching an event , An array of information containing touch points on the screen . |
| attribute | type | explain |
|---|---|---|
| globalX | number | From the top left corner of the screen ( The status bar is not included ) Lateral distance . The top left corner of the screen is the origin . |
| globalY | number | From the top left corner of the screen ( The status bar is not included ) Longitudinal distance . The top left corner of the screen is the origin . |
| localX | number | Horizontal distance from the upper left corner of the touched component . The upper left corner of the component is the origin . |
| localY | number | The longitudinal distance from the upper left corner of the touched component . The upper left corner of the component is the origin . |
Implementation process
hml part :
css part :
js part : By dynamically changing child elements width Width to achieve slider Slider effect ; To Xiao Yuan dot Set absolute positioning relative to its parent element , Through dynamic change left The value of causes the circle to move , Handle element width The width of is assigned to the variable dotLeft, You can achieve the effect that the small circle moves with the slider .
summary
This article is my study of Hongmeng animation API One of the exercises , It is also a commonly used component , The following functions need to be improved , For example, in the style 、 Functions, etc , I hope I can learn more about Hongmeng with you , Progress together .
For more original content, please pay attention to : China soft International HarmonyOS Technical team
Beginner to master 、 Skills to cases , Systematic sharing HarmonyOS Development technology , Welcome to contribute and subscribe , Let's move forward hand in hand to build Hongmeng ecology .
Want to know more about open source , Please visit :
边栏推荐
- 【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
- Simulation Implementation of list
- Talk about programmers learning English again
- Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?
- How to use kotlin flow in Android projects
- Gan series of confrontation generation network -- Gan principle and small case of handwritten digit generation
- 做好项目管理的10个关键点和5大措施
- Introduction to cesium
- Room database migration
- Summary of differences between data submission type request payload and form data
猜你喜欢

线代(矩阵‘)

Completely replace the redis+ database architecture, and JD 618 is stable!
![[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x](/img/7e/1d27e3f1856ab8c6cbfc5221c717bb.png)
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x

Huawei wireless device configuration wpa2-802.1x-aes security policy

cesium简介

New version 8.6 SEO quick release system (can be built at source level)
![[unity introduction program] basic concepts - 2D collider collider 2D](/img/cf/a546238a5eaf4707006ecf1b7f19c6.png)
[unity introduction program] basic concepts - 2D collider collider 2D

钉钉最新版,怎么清除登录手机号历史记录数据

Use cyclegan to train self-made data sets, popular tutorials, and get started quickly
![[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector](/img/b0/ef084f4391795a1369b0f46a2de8d6.png)
[unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector
随机推荐
NLP hotspots from ACL 2022 onsite experience
Gan series of confrontation generation network -- Gan principle and small case of handwritten digit generation
nanodet训练时出现问题:ModuleNotFoundError: No module named ‘nanodet‘的解决方法
for循环与if判断语句的运用
Hikaricp connection pool does not operate for a period of time, and the data is automatically disconnected
集群聊天服务器:项目问题汇总
GBase 8a中关于--skip-networking 问题
[ES6] function parameters, symbol data types, iterators and generators
First, how about qifujin
Common cross domain scenarios
Talk about programmers learning English again
JS cannot get content disposition in headers
[unity entry program] make my first little game
【Unity入门计划】制作我的第一个小游戏
[programmer 2 Civil Servant] summary of some common problems about system research
Introduction to Manhattan distance
New functions of shixizhi are online. These new functions are online in June. Can you use them?
How to use network installation to deploy multiple virtual servers in KVM environment
Lidar construction map (overlay grid construction map)
[paper notes] progressive layered extraction (PLE): a novel multi task learning (MTL) model for personalized