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

492
Views
This is the code to stop zoomin of browser using controll+scroll
import { useEffect } from "react";
import "./styles.css";

export default function App() {
  useEffect(() => {
    const handleWheel = (e) => {
      if (e.ctrlKey || e.metaKey) e.preventDefault();
      console.log(e);
    };
    window.addEventListener("wheel", handleWheel, { passive: false });
    return () => {
      window.removeEventListener("wheel", handleWheel, { passive: true });
    };
  }, []);

  return (
    <div className="App">
      <div className="hover">Hover me </div>
    </div>
  );
}

Can someone explain me what is the roll of {passive:false} in this code or{passive:true} in the code

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

According to MDN, setting the option passive: false tells the browser that the handler might call .preventDefault() to cancel the default action for the event.
It also says that in general passive: false is the default, but some browsers make passive: true to be the default for certain events, including 'wheel' events, so setting it to false is necessary for being consistent across all browsers.

As for setting passive: true when calling .removeEventListener() - I don't see a reason. By what I understand from MDN, it is supposed to be ignored completely, though on some browser releases it might prevent the removal of the handler when it doesn't match the original options in the call to .addEventListener().

about 4 years ago · Santiago Gelvez 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!