当前位置:网站首页>Achieve animation effect through event binding
Achieve animation effect through event binding
2022-07-04 17:48:00 【richest_ qi】
List of articles
Antecedents feed
The types of events involved in this example are :
touchstart, Finger touch action Start Trigger when .touchmove, After touching the fingers Move Trigger when .touchend, Finger touch action end Trigger when .
Event triggered , The event handler function will receive an event object , The attributes contained in the event object vary slightly depending on the type of event , among , The attributes of rain and dew are :
type, Event type .timeStamp, Time stamp when the event was generated .target, It's an object , Contains the following properties :id, Of the event source component id.dataset, On the event source component by data- A collection of custom properties at the beginning .
currentTarget, It's an object , Contains the following properties :id, Of the current component id.dataset, The current component consists of data- A collection of custom properties at the beginning .
mark, Event marker data .
In addition to the above basic attributes ,TouchEvent The event object of also contains the following properties :
touches, A collection of touch point information currently on the screen .touchesIs an array , Each array element is a Touch object , Indicates the touch point currently on the screen .Touch Object contains the following properties :identifier, value type , Is the identifier of the touch point .pageX, Horizontal distance from the upper left corner of the document .pageY, The vertical distance from the upper left corner of the document .clientX, The horizontal distance from the upper left corner of the visible area of the page .clientY, The vertical distance from the upper left corner of the visible area of the page .
changedTouches, Array of currently changing touchpoint information .
Applet project
The main files involved in the code are :
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js

app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": " home page ",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
pages/index/index.wxml
<view class="indexContainer">
<view class="header"></view>
<view class="content" bindtouchstart="handleTouchStart" bindtouchmove="handleTouchMove" bindtouchend="handleTouchEnd" style="transform: translateY({
{
moveDistance}}rpx);transition: {
{
transitionSettings}};" >
<image src="/static/images/arc.png"></image>
</view>
</view>
pages/index/index.wxss
.indexContainer{
padding: 0 20rpx;
}
.header{
margin-top: 10rpx;
background: lightskyblue;
height: 300rpx;
border-radius: 10rpx;
}
.content{
margin-top: -100rpx;
height: 600rpx;
background: #f7f7f7;
border-bottom-right-radius: 10rpx;
border-bottom-left-radius: 10rpx;
position: relative;
}
.content image{
position: absolute;
top: -40rpx;
width: 100%;
height: 40rpx;
}
pages/index/index.js
let startY = 0;
let endY = 0;
let distance = 0;
let MIN_DIS = 0;
let MAX_DIS = 80
Page({
data:{
moveDistance:0,
transitionSettings:"none"
},
handleTouchStart(e){
// console.log("touch start");
startY = e.touches[0].clientY;
this.setData({
transitionSettings:"none"
})
},
handleTouchMove(e){
// console.log("touch move");
endY = e.touches[0].clientY;
distance = endY - startY;
if(distance < MIN_DIS) return;
if(distance > MAX_DIS) distance = MAX_DIS;
this.setData({
moveDistance:distance
})
},
handleTouchEnd(){
// console.log("touch end");
this.setData({
moveDistance:0,
transitionSettings:"transform .5s linear"
})
}
})
Related links
边栏推荐
- Talk about seven ways to realize asynchronous programming
- Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
- 解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
- 正则表达式
- Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
- 图像检索(image retrieval)
- shell脚本的替换功能实现
- gatling 之性能测试
- Electronic pet dog - what is the internal structure?
- Great Wall Securities security does not open a securities account
猜你喜欢

整理混乱的头文件,我用include what you use

要上市的威马,依然给不了百度信心

With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games

ble HCI 流控机制

Superscalar processor design yaoyongbin Chapter 5 instruction set excerpt

RecastNavigation 之 Recast

What if Kaili can't input Chinese???

What is low code development?

MVC mode and three-tier architecture

解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
随机推荐
Superscalar processor design yaoyongbin Chapter 6 instruction decoding excerpt
Display opencv drawn pictures on MFC picture control control
Difference between redis' memory obsolescence strategy and expiration deletion strategy
Pytoch deep learning environment construction
大规模服务异常日志检索
Master the use of auto analyze in data warehouse
[system analyst's road] Chapter 7 double disk system design (structured development method)
La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.
Developers, MySQL column finish, help you easily from installation to entry
【Proteus仿真】基于VSM 串口printf调试输出示例
超标量处理器设计 姚永斌 第7章 寄存器重命名 摘录
Detectron2 installation method
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
无心剑中译伊丽莎白·毕肖普《一门技艺》
长城证券安全不 证券开户
要上市的威马,依然给不了百度信心
PingCode 性能测试之负载测试实践
Cocoscreator event dispatch use
【系统分析师之路】第七章 复盘系统设计(结构化开发方法)
高中物理:力、物体和平衡