Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Can I use preventDefault to my event with passive equal true?

I've came across to the next article, there I found example with blocking scroll event:

document.body.addEventListener('pointermove', event => {
  if (event.cancelable) {
      event.preventDefault(); // block the native scroll
      /*
      *  do what you want the application to do here
      */
  }
}, {passive: true});

but, it doesn't work, by the way I see illogicality using preventDefault in passive: true event. What is going on, anyone would explain to me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No, that's the point of passive. From MDN's documentation for addEventListener:

passive

A boolean value that, if true, indicates that the function specified by listener will never call preventDefault(). If a passive listener does call preventDefault(), the user agent will do nothing other than generate a console warning. See Improving scrolling performance with passive listeners to learn more.

And similarly, from the specification:

When set to true, options’s passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

The article would appear to be mistaken, or referring to situations that are not yet standardized (as they mention something about horizontal scrolling being underway while vertical scrolling starts).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!