[英]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%", 持續時間: 2 });
t1.to(".div-second", { ease: "power2.in", x: "-300%", 持續時間: 2 },"-=2");
t1.to(".div-third", { ease: "power2.in", x: "-400%", 持續時間: 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");
讓 callOne = true; 讓 hamburger = document.getElementById("hamburger");
hamburger.addEventListener("點擊", (e) => {toggleFct();});
function one() {t1.play(0);callOne = false;}
function 二(){t0.play(0); callOne = 真;}
function toggleFct() { callOne? 一二();}
當我嘗試執行以下操作時:
let callOne = true;
function one() {console.log("one");callOne = false;}
function two() {console.log("two"); callOne = true;}
function toggleFct() { callOne ? one() : two();}
它工作得很好......
順便說一句,你可以重寫
hamburger.addEventListener("click", (e) => {toggleFct();});
作為...
hamburger.addEventListener("click", toggleFct)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.