[英]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 }); let t1 = gsap.timeline({ paused: true, reversed: true });
t1.to(".div-first", { ease: "power2.in", x: "-200%", duration: 2 }); t1.to(".div-first", { ease: "power2.in", x: "-200%", 持续时间: 2 });
t1.to(".div-second", { ease: "power2.in", x: "-300%", duration: 2 },"-=2"); t1.to(".div-second", { ease: "power2.in", x: "-300%", 持续时间: 2 },"-=2");
t1.to(".div-third", { ease: "power2.in", x: "-400%", duration: 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(header, { ease: "power2.in", x: "-400%", duration: 2 }, "-=2");
t1.to(wrap, { 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 }); let t0 = gsap.timeline({ paused: true, reversed: true });
t0.to(".div-first", { ease: "power2.in", x: "100%", duration: 2 }); 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-second", { ease: "power2.in", x: "200%", duration: 2 }, "-=2");
t0.to(".div-third", { ease: "power2.in", x: "300%", 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(header, { ease: "power2.in", x: "400%", duration: 2 }, "-=2");
t0.to(wrap, { ease: "power2.in", x: "0%", duration: 2 }, "-=2"); t0.to(wrap, { ease: "power2.in", x: "0%", duration: 2 }, "-=2");
let callOne = true;让 callOne = true; let hamburger = document.getElementById("hamburger");让 hamburger = document.getElementById("hamburger");
hamburger.addEventListener("click", (e) => {toggleFct();}); hamburger.addEventListener("点击", (e) => {toggleFct();});
function one() {t1.play(0);callOne = false;} function one() {t1.play(0);callOne = false;}
function two() {t0.play(0); function 二(){t0.play(0); callOne = true;} callOne = 真;}
function toggleFct() { callOne? function toggleFct() { callOne? one(): two();}一二();}
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.