'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");



Solution 1:[1]

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();}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mouloud Zerouti