i want to toggle between two functions this code works only one time but i want to make it work each time i click

Mouloud Zerouti
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");

Hangover Sound Sound

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)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I want to apply for-each loop on two models at same time Asp.Net MVC

I want to make two Queries into one by a variable

Context Menu (RightClickMenu) Excel: Works only in one book, I want it to work everywhere

Will pop scope widget only works for the last screen of my project I want to work it on each page or specific pages

I want to be able to toggle the background color of the two divs with a button click

i want to write a python code that calculates time

I want to highlight the syntax of my MutiAutoCompleteTextView for each time text is changed

i am beginner and having problem with this!. I want output to print in seperate subLists in the mainList only one time

I want to onchange "change" just one time

I want to put these two functions in one function

How can I execute some part of code at time that I want?

I want to be able to change each picture to appear in the same place on the screen every time i click a button

I want to create combo box when i click a button each time

I want to make a Javascript Quiz that randomizes the questions each time

I want to start a new animation every time I click with requestFrameAnimation

I want to write a macro that only works in one word document

I want to check the time interval

I'm trying to create a Calculator and I want to make my code such that When I click on the arithmetic Operators, I want them to run only once

I want to make this code specific to only one role, how can I do it?

I want to express the below "I have only one of the two" in TypeScript

when i click a button second time my label want to dissappear

I want to replace the inp element to span element the code is working fine for 1 time only when I click 2nd time on the check btn value goes undefined

If I run my code it works well but I want it to show me a different output when I input start for the second time in the terminal

I want to set a "for" counter for each array in only one "for" declaration, rather than create two "for" declarations. How can I make it possible?

My code receives the message from the queue multiple time, I want to receive it only one time. How can I do it?

Trying to toggle a Redux boolean on a button click, however the toggle only works the first time and I'm not sure why

I have a dataframe in which one columns contains day and time and I want to put each day and its time in different column

Is it more efficient to loop over a list each time or remove elements as I find the one I want in Java?

I want to implement multiple analysis statements in bison, but each time it will succeed only when it is executed for the first time