当前位置:网站首页>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 :
边栏推荐
- New functions of shixizhi are online. These new functions are online in June. Can you use them?
- Million level element optimization: real-time vector tile service based on PG and PostGIS
- Google Earth engine - Landsat 1985-2020 ecological remote sensing index resi calculation
- Day by day, month by month | Shenzhen potential technology released the extreme accelerated version of molecular docking engine uni docking
- New version 8.6 SEO quick release system (can be built at source level)
- SAP queries open Po (open purchase order)
- When importing data in batches, you always prompt "failure reason: SQL parsing failure: parsing file failure:: null". What's the matter?
- Cluster chat server: summary of project problems
- Design of workflow system
- [paper notes] next vit: next generation vision transformer for efficient deployment in real industry
猜你喜欢
![[paper notes] effective CNN architecture design guided by visualization](/img/aa/aeeac3f970eac7f110987c523602c8.png)
[paper notes] effective CNN architecture design guided by visualization

集群聊天服务器:项目问题汇总

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

Cluster chat server: summary of project problems

【Unity入门计划】基本概念-2D刚体Rigidbody 2D

QT learning diary 20 - aircraft war project

冰冰学习笔记:类与对象(上)

Lidar construction map (overlay grid construction map)

纳米数据足球数据,足球赛事比分,体育数据api,卡塔尔世界杯

Nano data, football data, football match scores, sports data API, Qatar world cup
随机推荐
diagramscene工程难点分析
When providing digital talent services, Xi Zhi quickly opened its own digital school for each organization
Learn when playing No 7 | don't study this holiday, study only
【程序员2公务员】四、常见问题
Nailing the latest version, how to clear the login phone number history data
Configuring WAPI certificate security policy for Huawei wireless devices
华为无线设备配置WAPI-证书安全策略
Completely replace the redis+ database architecture, and JD 618 is stable!
Leetcode skimming: dynamic programming 06 (integer splitting)
【Unity入门计划】基本概念-触发器 Trigger
How does uxdb extract hours, minutes and seconds from date values?
Talk about programmers learning English again
Robot Framework移动端自动化测试----01环境安装
PADS导出gerber文件
深度学习训练和测试时出现问题:error: the following arguments are required: --dataroot,解决:训练文件的配置方法和测试文件的配置方法
Problems in deep learning training and testing: error: the following arguments are required: --dataroot, solution: the configuration method of training files and test files
大佬秋招面经
Analysis of difficulties in diagramscene project
Introduction to Manhattan distance
Incremental crawler in distributed crawler