当前位置:网站首页>通过事件绑定实现动画效果
通过事件绑定实现动画效果
2022-07-04 16:03:00 【richest_qi】
前情提要
本例涉及的事件类型有:
touchstart
,手指触摸动作开始 时触发。touchmove
,手指触摸后移动 时触发。touchend
,手指触摸动作结束 时触发。
事件触发时,事件处理函数会接收到一个事件对象,该事件对象包含的属性因事件类型不同而有些许差异,其中,雨露均沾的属性有:
type
,事件类型。timeStamp
,事件生成时的时间戳。target
,是一个对象,包含如下属性:id
,事件源组件的id。dataset
,事件源组件上的由data-开头的自定义属性组成的集合。
currentTarget
,是一个对象,包含如下属性:id
,当前组件的id。dataset
,当前组件上由data-开头的自定义属性组成的集合。
mark
,事件标记数据。
除了以上基础属性,TouchEvent的事件对象还包含如下属性:
touches
,当前停留在屏幕上的触摸点信息的集合。touches
是一个数组,每个数组元素是一个Touch对象,表示当前停留在屏幕上的触摸点。Touch对象包含如下属性:identifier
,数值类型,是触摸点的标识符。pageX
,距离文档左上角的横向距离。pageY
,距离文档左上角的纵向距离。clientX
,距离页面可视区域左上角的横向距离。clientY
,距离页面可视区域左上角的纵向距离。
changedTouches
,当前变化的触摸点信息的数组。
小程序项目
代码涉及的主要文件有:
- app.json
- pages/index/index.wxml
- pages/index/index.wxss
- pages/index/index.js
app.json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarBackgroundColor": "#971a22",
"navigationBarTitleText": "首页",
"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"
})
}
})
相关链接
边栏推荐
- New technology releases a small program UNIPRO to meet customers' mobile office scenarios
- Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
- 完美融入 Win11 风格,微软全新 OneDrive 客户端抢先看
- It's too convenient. You can complete the code release and approval by nailing it!
- CocosCreator事件派发使用
- 利用win10计划任务程序定时自动运行jar包
- Pytorch deep learning quick start tutorial
- Rainfall warning broadcast automatic data platform bwii broadcast warning monitor
- About the pit of firewall opening 8848 when Nacos is started
- 简单易用的地图可视化
猜你喜欢
Solution of commercial supply chain coordination system in the mineral industry: build a digital intelligent supply chain platform to ensure the safe supply of mineral resources
解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替
Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
The Ministry of human resources and Social Security announced the new construction occupation
ble HCI 流控机制
【HCIA持续更新】WLAN工作流程概述
太方便了,钉钉上就可完成代码发布审批啦!
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
Using win10 scheduling task program to automatically run jar package at fixed time
【HCIA持续更新】网络管理与运维
随机推荐
Is it safe for Bank of China Securities to open an account online?
图像检索(image retrieval)
聊聊异步编程的 7 种实现方式
leetcode:421. The maximum XOR value of two numbers in the array
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
电子宠物小狗-内部结构是什么?
Summary of tx.origin security issues
Image retrieval
Firewall basic transparent mode deployment and dual machine hot standby
What grade does Anxin securities belong to? Is it safe to open an account
上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
[Huawei HCIA continuous update] SDN and FVC
网页游戏引擎
【测试开发】软件测试——基础篇
kaili不能输入中文怎么办???
New technology releases a small program UNIPRO to meet customers' mobile office scenarios
Load test practice of pingcode performance test
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly