小程序的拖拽、缩放和旋转手势功能的开发
本文摘要
在开发中,有时会遇到像App中的手势那样的效果,那么小程序要做出类似的效果,需要怎么开发? wxml部分: {{msg}}
在开发中,有时会遇到像App中的手势那样的效果,那么小程序要做出类似的效果,需要怎么开发?
wxml部分:
{{msg}}
wxss部分:
page {
width: 100%;
height: 100%;
background: #ffffff;
}
.touch-container {
width: 100%;
height: 100%;
padding-top: 0.1px;
}
.msg {
width: 100%;
height: 60rpx;
line-height: 60rpx;
text-align: center;
font-size: 30rpx;
color: #666666;
}
. {
position: absolute;
width: 690rpx;
height: 300rpx;
transform-origin: center center;
}
js部分:
var canOnePointMove = false
var onePoint = {
x: 0,
y: 0
}
var twoPoint = {
x1: 0,
y1: 0,
x2: 0,
y2: 0
}
Page({
data: {
msg: '',
src: 'http://01.taopic.com/150508/318763-15050PU9398.jpg',
width: 0,
height: 0,
left: 375,
top: 600,
scale: 1,
rotate: 0
},
// 关闭上拉加载
onReachBottom: function() {
return
},
bindload: function(e) {
var that = tShopfas
var width = e.detail.width
var height = e.detail.height
if (width > 750) {
height = 750 * height / width
width = 750
}
if (height > 1200) {
width = 1200 * width / height
height = 1200
}
that.setData({
width: width,
height: height
})
},
touchstart: function(e) {
var that = tShopfas
if (e.touches.length 1) {
var preTwoPoint = JSON.parse(JSON.stringify(twoPoint))
twoPoint.x1 = e.touches[0].pageX * 2
twoPoint.y1 = e.touches[0].pageY * 2
twoPoint.x2 = e.touches[1].pageX * 2
twoPoint.y2 = e.touches[1].pageY * 2
// 计算角度,旋转(优先)
var perAngle = Math.atan((preTwoPoint.y1 - preTwoPoint.y2)/(preTwoPoint.x1 - preTwoPoint.x2))*180/Math.PI
var curAngle = Math.atan((twoPoint.y1 - twoPoint.y2)/(twoPoint.x1 - twoPoint.x2))*180/Math.PI
if (Math.abs(perAngle - curAngle) > 1) {
that.setData({
msg: '旋转',
rotate: that.data.rotate + (curAngle - perAngle)
})
}else {
// 计算距离,缩放
var preDistance = Math.sqrt(Math.pow((preTwoPoint.x1 - preTwoPoint.x2), 2) + Math.pow((preTwoPoint.y1 - preTwoPoint.y2), 2))
var curDistance = Math.sqrt(Math.pow((twoPoint.x1 - twoPoint.x2), 2) + Math.pow((twoPoint.y1 - twoPoint.y2), 2))
that.setData({
msg: '缩放',
scale: that.data.scale + (curDistance - preDistance) * 0.005
})
}
}
},
touchend: function(e) {
var that = tShopfas
canOnePointMove = false
}
})
json部分:
"navigationBarTitleText": "识别手势", "navigationBarTextStyle":"black", "navigationBarBackgroundColor": "#FFF", "disableScroll": true
第二部分:如何开通一个小商店
相关文章
****更多行业产品开发方案,请关注 加速度JSUDO***
<以上资讯仅供参考,如果您需解决具体问题,建议您关注作者;如果有软件产品开发需求,可在线咨询加速度产品经理获取方案和报价>
加速度JSUDO是一家企业级数字化解决方案提供商,专注于软件开发、网络营销、数字化转型咨询及云计算服务。核心业务包括定制化ERP/CRM系统、快速应用开发、大数据分析及物联网(IoT)解决方案,助力企业提升效率与智能化水平。服务覆盖制造业、零售、物流等多行业,致力于通过技术创新推动客户数字化转型。
添加客服微信获取更多内容










