Reputation: 2035
I created a draggable item with the draggable ui. Now, when dragging over a specific element I want to trigger a function startSwipe()
. Untill here all goes well... But after I stop dragging, the function stays active and each time I hover the element again the function triggers again.
I did some research, and come across this question How can I exit from a javascript function?
But I'm having a hard time to implement it in my stuff.
Here are the code:
function startDragging() {
var $calendar = $(".calendar-tasks");
$("li.allowed-to-drag", $calendar).draggable({
revert: "invalid",
helper: function (event, ui) {
return $("<div class='task-image' style='z-index: 10000;'><span class='icon-pushpin'></span></div>").appendTo("body");
},
cursorAt: { left: 25 },
zIndex: 100,
start: function (event) {
$(".previous-week a, .next-week a, .previous-month a, .next-month a").addClass("swipeable");
startSwipe();
},
stop: function (event) {
$(".previous-week a, .next-week a, .previous-month a, .next-month a").removeClass("swipeable");
stopSwipe(); // A test if this would work...
}
});
}
function startSwipe() {
$(".previous-week a, .next-week a, .previous-month a, .next-month a").mouseover(function(){
console.log("hovered");
});
return;
}
function stopSwipe() {
return;
}
Any help is greatly appreciated.
jsFiddle: https://jsfiddle.net/amvk45nh/2/
Upvotes: 0
Views: 266
Reputation: 2424
On the startSwipe()
function you are binding an event, so you should unbind it when you want it to stop. You could try this:
function stopSwipe() {
$(".previous-week a, .next-week a, .previous-month a, .next-month a").unbind('mouseover');
}
Upvotes: 2