Closed Matt-Deacalion closed 4 years ago
Is there any troubles if the moving
event still bound?
It wouldn't make unnecessary calls to the moving
callback, making the code more efficient. The main reason though, is that it feels more obvious that the moving
callback should only be concerned with movement when "swiping".
An example would be if we wanted an element to follow the "cursor", we could set the element's x
and y
within the moving
callback and we're done. But if moving
is always called, we have to bind it in start
and then unbind it on end
or else the element will continue tracking the cursor.
I can't understand your problem clearly. I'm not good at English in fact. Reffer to https://github.com/jerrybendy/vue-touch-events/blob/master/index.js#L112 , only when touchMoved
is true
, the moving
event will be triggered. And the touchMoveEvent
function is called when native touchmove
or mousemove
event triggered. So I think your problem doesn't exist. Moving
event wouldn't be triggered when you release your finger from a touch screen.
You may be right. The README.md
does say that moving
is a "Continuously triggering Event". I got confused because it doesn't track movement from the beginning.
Example: https://jsfiddle.net/kvfm8xsr/
Moving
often works with start
and end
. In your example, you should set clicked
to true
when start
triggered and set to false
when end
triggered.
<div
v-touch:start="() => this.clicked = true"
v-touch:end="() => this.clicked = false"
v-touch:moving="movingHandler"
></div>
movingHandler: function (e) {
if (this.clicked) {
[this.x, this.y] = [e.x - 25, e.y - 75];
}
}
When initiating a
touch
, themoving
event fires continuously as I move around. It continues to fire after I end the touch. Should themoving
event listener be removed atend
?