Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda