Reputation: 707
I have this jQuery that does when the user is clicking the slider get the coordinates but when he lifts up the mouse the function still runs
$("slider").mousedown(function(){
$(this).mousemove(function(e){
console.log(e.clientX);
});
};
But when the users lift up the mouse the code still runs and still logs the coordinates.
Upvotes: 0
Views: 271
Reputation: 3339
Do like this:
$("slider").mousedown(function(){
$(this).mousemove(function(e){
console.log(e.clientX);
});
};
$("slider").mouseup(function(){
$(this).unbind("mousemove");
});
Upvotes: 1
Reputation: 2269
Your mousedown function changes the mousemove function permanently. So you want to add something like this:
$("slider").mouseup(function(){
$(this).unbind("mousemove")
};
Upvotes: 1