我的下面的代码有问题,我有幸运之轮.但是,我只想转一圈.

此代码

谢谢你的帮助


  // Process
  box.style.setProperty("transition", "all ease 5s");
  box.style.transform = "rotate(" + Hasil[0] + "deg)";
  element.classList.remove("animate");
  setTimeout(function () {
    element.classList.add("animate");
  }, 5000);
  

  // ALert
 
  setTimeout(function () {
    applause.play();
    
    swal(
      "Congratulations",
      "You Won The " + SelectedItem + ".",
      "success"
    ).then(function(){
      // window.location.href= "submit.php?id=($id)";
      
  });
  }, 5500) 
  
  // Delay and set to normal state
  setTimeout(function () {
    box.style.setProperty("transition", "initial");
    box.style.transform = "rotate(90deg)";
  }, 6000);

推荐答案

要将车轮旋转限制为1,请使用boolean标志跟踪它,以判断车轮是否已经旋转.所以假设click事件激发后触发的回调是spinWheel().

// Add this line at the beginning of your script
let hasWheelSpun = false;

// Process
function spinWheel() {
  // Check if the wheel has already been spun
  if (hasWheelSpun) {
    return;
  }

  // Set hasWheelSpun to true to indicate the wheel has been spun
  hasWheelSpun = true;

  box.style.setProperty("transition", "all ease 5s");
  // ...rest of your code

  // Alert
  // ...rest

  // Delay and set to normal state
  // ...rest
}

document.getElementById("spinButton").addEventListener("click", spinWheel);

Javascript相关问答推荐

Next.js Next/Image图像隐含性有任何类型-如何修复?

D3多线图显示1线而不是3线

我可以使用CSS有效地实现最大宽度=100%和最大高度=100%,而无需父母有明确的/固定的宽度和高度,替代方法吗?

如何在angular中从JSON值添加动态路由保护?

react—router v6:路由没有路径

成功完成Reducers后不更新状态

在拖放时阻止文件打开

S文本内容和值不必要的不同

Puppeteer上每页的useProxy返回的不是函数/构造函数

在JS中动态创建对象,并将其追加到HTML表中

Reaction-SWR-无更新组件

使用Document.Evaluate() Select 一个包含撇号的HTML元素

如何通过Axios在GraphQL查询中发送数组

如何修复错误&语法错误:不能在纯react 项目中JEST引发的模块&之外使用导入语句?

如何使用puppeteer操作所有选项

如何在Highlihte.js代码区旁边添加行号?

每隔一行文本段落进行镜像(Boustrophedon)

需要从对象生成列表

暂停后只有一次旋转JS

JavaScript structuredClone在Chrome/Edge中获得了非法调用,但在NodeJS中没有