Reputation: 836
Scenario: user clicks on a element, then drags it. Dragging ends elsewhere though. I noticed that when this happens, if I listen to the element that's being dragged, it won't trigger anything unless the cursor is released on the same element when dragging finishes.
How do I trigger an event that starts on an element but ends anywhere else on document?
$('#hotels-slider-handle').on('mouseup touchend click', function() {
$('#booking-input').trigger('change');
});
Upvotes: 0
Views: 1408
Reputation: 836
in answer to Cerlin Boss who commented to my original post above... this is what I came up with and works well (what I need to trigger gets triggered just fine) - I was looking for more efficient solutions though (ignore the jQuery delays, they're necessary in my scope)
var bookingFormInputs = $('#booking-input'),
hotelsSlider = $('#hotels-slider');
$('#hotels-slider-handle').on('mousedown touchstart', function() {
$(document).delay(300).one('mouseup touchend', function() {
$(bookingFormInputs).delay(600).trigger('change');
});
$(hotelsSlider).delay(300).one('mouseleave', function() {
$(document).on('mouseup touchend', function() {
$(bookingFormInputs).delay(300).trigger('change');
});
});
});
Upvotes: 0