在写可拖动的菜单按钮碰到一个问题。
当用catchtouchstart和catchtouchmove事件绑定菜单按钮的拖动时,bindtap事件失效了。
代码如下:
<view catchtouchstart='buttonStart' catchtouchmove='buttonMove' class='menu_block' bindtap='toggleLeft1' style='top:{{buttonTop}}px;left:{{buttonLeft}}px;'>
<i-icon type="other" size="28" color="#80848f" />
</view>
搜索一番,找到一个处理方法:
tap,touchstart,touchend的事件触发顺序为start→end→tap
所以问题在于catchtouchstart,catchtouchend后事件被阻止了,tap捕获不到。
改为bindtouchstart,bindtouchend后问题得以解决。
自己的代码里把catchtouchstart修改成bindtouchstart。问题解决了
<view bindtouchstart='buttonStart' catchtouchmove='buttonMove' class='menu_block' bindtap='toggleLeft1' style='top:{{buttonTop}}px;left:{{buttonLeft}}px;'>
<i-icon type="other" size="28" color="#80848f" />
</view>