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

530
Visualizações
Error: $ not defined - Javascript / React

I am in the process of converting a html/css gsap navbar to React. This is returning the following error:

error '$' is not defined no-undef

I cannot seem to find any other guides on the matter that seem to relate to my issue.

import React from "react";
import "../components/Navbar.css";
import { gsap } from "gsap";
import { ExpoScaleEase, RoughEase, SlowMo } from "gsap/EasePack";

gsap.registerPlugin(ExpoScaleEase, RoughEase, SlowMo);

var t1 = gsap.timeline({ paused: true });

t1.to(".one", 0.8, {
    y: 6,
    rotation: 45,
    ease: "power3.inout"
});
t1.to(".two", 0.8, {
    y: -6,
    rotation: -45,
    ease: "power3.inout",
    delay: -0.8
});
t1.to(".menu", 2, {
    top: "0%",
    ease: "power3.inout",
    delay: -2
});
t1.staggerFrom(".menu ul li", 2, { x: -200, opacity: 0, ease: "power3.inout" }, 0.3);

t1.reverse();
$(document).on("click", ".toggle-btn", function () {
    t1.reversed(!t1.reversed());
});
$(document).on("click", "a", function () {
    t1.reversed(!t1.reversed());
});

export const Navbar = () => {
    <div>
        <div className="toggle-btn">
            <span className="one"></span>
            <span className="two"></span>
        </div>

        <div className="menu">
            <div className="data">
                <ul>
                    <li><a href="/">Return Home ➔</a></li>
                    <li><a href="/">Companies</a></li>
                    <li><a href="/">About</a></li>
                    <li><a href="/">Contact Us</a></li>
                </ul>
            </div>
        </div>
    </div>
}

export default Navbar;
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There are two places where you reference $:

$(document).on("click", ".toggle-btn", function () {
    t1.reversed(!t1.reversed());
});
$(document).on("click", "a", function () {
    t1.reversed(!t1.reversed());
});

This looks like jQuery, so you need to add the jQuery library or convert this to vanilla js.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can't use $(document).on without importing JQuery.

You either need to import JQuery, or find another solution without using $(document).on

Solution using Javascript only

Replace this:

$(document).on("click", ".toggle-btn", function () {
    t1.reversed(!t1.reversed());
});

with this:

document.addEventListener('click', function(event) {
    if (event.target.classList.contains("toggle-btn")) {
      t1.reversed(!t1.reversed());
    }
});
about 4 years ago · Juan Pablo Isaza 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