Scenario :
- I use this code for a page and apply it on click event,
now I have trouble to remove it from page (same way, on click). - How do I do that?
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, {
passive: false
});
Scenario :
document.addEventListener('touchmove', function(e) {
e.preventDefault();
}, {
passive: false
});
Use a named callback function touchMove when binding/unbinding the event listener to addEventListener and removeEventListener methods.
The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process;
var touchMove = function(e){
e.preventDefault();
};
document.addEventListener('touchmove', touchMove, { passive: false });
document.removeEventListener('touchmove', touchMove);
e.preventDefault(). Setting passive: true will ignore e.preventDefault() calls.passive: false code, so where should I put it?, tried this with the rest of it (add and remove lines added to on click event) but this it not working for me, this is the code from my attempt: var touchMove = function(e){ e.preventDefault(); }, { passive: false }; @dysfuncSo initialize your button to add the event listener on click to the touchmove area, then remove the click function from the button and set it up so the next cick adds the remove event listener for removing the click and touch event. Basically toggle the event listener on the button and the div.
//Touchmove action
function preDef(e) {
e.preventDefault();
}
//Add the touchmove action and toggle the button to remove the action
function addE(e) {
e.target.removeEventListener('click', addE, {passive: false});
e.target.addEventListener('click', removeE, {passive: false});
document.addEventListener('touchmove', preDef, {passive: false});
}
//Remove the touchmove action and toggle the button to add the action
function removeE(e) {
e.target.removeEventListener('click', removeE, {passive: false});
e.target.addEventListener('click', addE, {passive: false});
document.removeEventListener('touchmove', preDef, {passive: false});
}
//Initialize the add action
document.getElementById('somebutton').addEventListener('click', addE, {passive: false});