当前位置:网站首页>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 :
边栏推荐
- [cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
- Cluster chat server: summary of project problems
- 【Unity入门计划】基本概念-GameObject&Components
- [programmer 2 Civil Servant] IV. common problems
- nanodet训练时出现问题:ModuleNotFoundError: No module named ‘nanodet‘的解决方法
- Quickly build a centralized logging platform through elk
- 【程序员2公务员】三、资源搜集
- 【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
- Common cross domain scenarios
- Design of workflow system
猜你喜欢

Summary of differences between data submission type request payload and form data

QT学习日记20——飞机大战项目

Line generation (matrix ')

Matlab self programming series (1) -- angular distribution function

【论文笔记】Progressive Layered Extraction (PLE): A Novel Multi-Task Learning (MTL) Model for Personalized
![[paper notes] effective CNN architecture design guided by visualization](/img/aa/aeeac3f970eac7f110987c523602c8.png)
[paper notes] effective CNN architecture design guided by visualization

【软件测试】包装简历从这几点出发、提升通过率
![[unity entry program] basic concept trigger](/img/16/cd0f8ae579627fc095935195136729.png)
[unity entry program] basic concept trigger

Bingbing's learning notes: classes and objects (Part 1)

纳米数据足球数据,足球赛事比分,体育数据api,卡塔尔世界杯
随机推荐
P1049 [NOIP2001 普及组 T4] 装箱问题
【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
Robot Framework移动端自动化测试----01环境安装
一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking
[unity introduction program] basic concept - preform prefab
Oracle19采用自动内存管理,AWR报告显示SGA、PGA设置的过小了?
【微信小程序】全局样式、局部样式、全局配置
【Unity入门计划】界面介绍(1)-Scene视图
Introduction to Manhattan distance
9 best engineering construction project management systems
[unity introduction program] basic concepts GameObject & components
"Game illustrated book": a memoir dedicated to game players
深度学习制作数据集时,从长视频中指定每隔多少帧提取一张图像到指定文件路径的方法
【Unity入门计划】基本概念-GameObject&Components
Room database migration
Nailing the latest version, how to clear the login phone number history data
Practical operation: elegant downtime under large-scale micro service architecture
[unity introduction program] basic concepts -2d rigid body 2D
Simulation Implementation of list
J1 常用的DOS命令(P25)