我一直在使用Simone P.M.的LikeCarousel (github.com/simonepm)作为创建调查表的基础,并在“喜欢”和“不喜欢”按钮中添加了“点击”功能。
但是,由于某种原因,如果您单击,第二个卡上的功能会触发两次,第三张卡上的会触发三次,等等。
我一直在绞尽脑汁找出原因,但是我什么都看不见!
this.like.addEventListener("click", (t) => {
this.onLike(t);
}));
onLike(t) {
console.log(t),
console.log("Answer", this.topCard.dataset.answer),
(this.topCard.style.transition = null),
this.nextCard && (this.nextCard.style.transition = null),
(this.topCard.style.transition = "transform 200ms ease-out"),
this.nextCard &&
(this.nextCard.style.transition = "transform 100ms linear"),
(this.topCard.style.transform =
"translateX(200%) translateY(-40%) rotate(20deg)"),
this.nextCard &&
(this.nextCard.style.transform =
"translateX(-50%) translateY(-50%) rotate(0deg) rotateY(0deg) scale(1)"),
setTimeout(() => {
this.board.removeChild(this.topCard), this.handle();
}, 200);
}
有什么想法吗?我在这里创建了一支笔: