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

209
Views
i want to toggle between two functions this code works only one time but i want to make it work each time i click
let callOne = true;
let hamburger = document.getElementById("hamburger");

hamburger.addEventListener("click", (e) => {toggleFct();});

function one() {t1.play();callOne = false;}

function two() {t0.play(); callOne = true;}

function toggleFct() { callOne ? one() : two();}

let t1 = gsap.timeline({ paused: true, reversed: true });

t1.to(".div-first", { ease: "power2.in", x: "-200%", duration: 2 });

t1.to(".div-second", { ease: "power2.in", x: "-300%", duration: 2 },"-=2");

t1.to(".div-third", { ease: "power2.in", x: "-400%", duration: 2 }, "-=2");

t1.to(header, { ease: "power2.in", x: "-400%", duration: 2 }, "-=2");

t1.to(wrap, { ease: "power2.in", x: "-400%", duration: 2 }, "-=2");

let t0 = gsap.timeline({ paused: true, reversed: true });

t0.to(".div-first", { ease: "power2.in", x: "100%", duration: 2 });

t0.to(".div-second", { ease: "power2.in", x: "200%", duration: 2 }, "-=2");

t0.to(".div-third", { ease: "power2.in", x: "300%", duration: 2 }, "-=2");

t0.to(header, { ease: "power2.in", x: "400%", duration: 2 }, "-=2");

t0.to(wrap, { ease: "power2.in", x: "0%", duration: 2 }, "-=2");

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

0

let callOne = true; let hamburger = document.getElementById("hamburger");

hamburger.addEventListener("click", (e) => {toggleFct();});

function one() {t1.play(0);callOne = false;}

function two() {t0.play(0); callOne = true;}

function toggleFct() { callOne ? one() : two();}

about 4 years ago · Juan Pablo Isaza Report

0

When I try to do the following :

let callOne = true;

function one() {console.log("one");callOne = false;}

function two() {console.log("two"); callOne = true;}

function toggleFct() { callOne ? one() : two();}

It works just fine...

btw you can rewrite

hamburger.addEventListener("click", (e) => {toggleFct();});

as...

hamburger.addEventListener("click", toggleFct)
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!