Reputation:
I wrote some javascript code that prevents scrolling on focus. How do I disable it after focus is lost?
Focus
e.preventDefault();
e.stopPropagation();
Focus out
e.preventDefault = false;
e.stopPropagatio = false;
Upvotes: 3
Views: 21213
Reputation:
Fixed by unbinding the event.
Focus
$('.form-control').focus(function() {
$('#element').on('scroll touchmove mousewheel', function(e){
e.preventDefault();
e.stopPropagation();
})
});
Focus out
$('.form-control').focusout(function() {
$('#element').unbind();
});
Upvotes: 4
Reputation: 288670
You can't undo preventDefault
nor stopPropagation
.
Just stop calling them, e.g.
var stopScroll = true;
element.addEventListener('scroll', function() {
if (stopScroll) {
e.preventDefault();
e.stopPropagation();
}
});
// ...
stopScroll = false;
function listener() {
e.preventDefault();
e.stopPropagation();
}
element.addEventListener('scroll', listener);
// ...
element.removeEventListener('scroll', listener);
Upvotes: 1