页面上有个fixed悬浮按钮,希望可以在页面上任意拖动位置,但是现在的问题是写出来的拖动效果特别不流畅(反应延迟),请问有什么好的办法解决?
<view class='helpbox' style="bottom:{{bottom}}px;right:{{right}}px;" catchtouchmove='setTouchMove'>
<image class='helpimg' src='/images/help.png'></image>
</view>
js代码:
setTouchMove:function(e){
var that = this;
var width = 35 * rpx;
var screenWidth = wx.getSystemInfoSync().windowWidth;
var screenHeight = wx.getSystemInfoSync().windowHeight;
var clientX = e.touches[0].clientX;
var clientY = e.touches[0].clientY;
//此处clientY与clientX为拖动悬浮窗超过设定的大小会返回默认显示位置
if (clientX < (screenWidth - width) && clientY < (screenHeight - width) && clientX > width && clientY > width) {
that.setData({
right: screenWidth - clientX - width,
bottom: screenHeight - clientY - width
})
} else {
return;
// that.setData({
// right: 0, //默认显示位置 left距离
// bottom: 0 //默认显示位置 top距离
// })
}
}
其实拖动动画是可以流畅的。确保一下几点:
打个广告,小程序需要监听复杂手势的话(双击,长按,旋转,等等),可以使用mian-touch, github地址为 https://github.com/Yrobot/mina-touch
由于小程序的逻辑和视图引擎是异步分离的,无法做到流畅。需要修改实现方式,或者不采取需要拖动的解决方案。
谢谢了
您好,请问您解决了吗这个问题
没有,暂时没有做这个功能了