How to leave the event if a given condition is reached?
example:
$('#element').draggabilly({
containment: true,
axis: 'x'
}).on('dragMove', function() {
let containerWidth = $(this).parent().width()
let buttonWidth = $(this).outerWidth()
let max = (containerWidth - buttonWidth) - 1 // count border right (1px)
// condiction
if ( $(this).position().left >= max ) {
console.log('limit reached')
return false // escape here!!! don't escaped!
}
}).on('dragEnd', function() {
let containerWidth = $(this).parent().width()
let buttonWidth = $(this).outerWidth()
let max = (containerWidth - buttonWidth) - 1 // count border right (1px)
// confirm condiction
if ( $(this).position().left >= max ) {
// do stuff...
} else {
// do stuff...
}
}).on('click', function() {
//...
})
I'm assuming that return on "move" would trigger "end"? Is there a correct method?
How to leave the event if a given condition is reached?
example:
I'm assuming that return on "move" would trigger "end"? Is there a correct method?