gpt4 book ai didi

javascript - 打开特定页面的 JavaScript 操作(轮盘赌)的结果

转载 作者:行者123 更新时间:2023-12-03 10:29:35 25 4
gpt4 key购买 nike

我正在将此轮盘赌的代码用于个人项目。轮盘赌一切正常,但我试图让轮盘赌的结果在同一窗口中打开特定页面。我不确定如何确定结果。例如,如果结果是 N,我不希望结果显示在页面上(就像当前那样),但希望打开一个页面。我尝试在最后添加一个函数来尝试使其工作,但无法弄清楚

下面是代码中的函数:

var options = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SES", "S", "SSW", "SW", "WSW", "W", "WWW", "NW", "NWW"];
var startAngle = 0;
var arc = Math.PI / (options.length / 2);
var spinTimeout = null;
var spinArcStart = 10;
var spinTime = 0;
var spinTimeTotal = 0;
var ctx;

document.getElementById("spin").addEventListener("click", spin);
function byte2Hex(n) {
var nybHexString = "0123456789ABCDEF";
return String(nybHexString.substr((n >> 4) & 0x0F,1)) + nybHexString.substr(n & 0x0F,1);
}

function drawRouletteWheel() {
var canvas = document.getElementById("canvas");
if (canvas.getContext) {
var outsideRadius = 200;
var textRadius = 160;
var insideRadius = 1;
}

function spin() {
spinAngleStart = Math.random() * 10 + 10;
spinTime = 0;
spinTimeTotal = Math.random() * 3 + 4 * 1000;
rotateWheel();
}

function rotateWheel() {
spinTime += 30;
if(spinTime >= spinTimeTotal) {
stopRotateWheel();
return;
}

var spinAngle = spinAngleStart - easeOut(spinTime, 0, spinAngleStart, spinTimeTotal);
startAngle += (spinAngle * Math.PI / 180);
drawRouletteWheel();
spinTimeout = setTimeout('rotateWheel()', 30);
}

function stopRotateWheel() {
clearTimeout(spinTimeout);
var degrees = startAngle * 180 / Math.PI + 90;
var arcd = arc * 180 / Math.PI;
var index = Math.floor((360 - degrees % 360) / arcd);
ctx.save();
ctx.font = '30px Roboto Condensed, Arial';
var text = options[index]
ctx.fillText(text, 250 - ctx.measureText(text).width / 2, 250 + 10);
ctx.restore();
}

function easeOut(t, b, c, d) {
var ts = (t/=d)*t;
var tc = ts*t;
return b+c*(tc + -3*ts + 3*t);
}

drawRouletteWheel();


Below is the approach I have taken to try and make this work:


function openDestinationResult() {
var NNE = "index.html";
var NE = "index.html";
var ENE = "index.html";
var E = "index.html";
var ESE = "index.html";
var SE = "index.html";
var SES = "index.html";
var S = "index.html";
var SSW = "index.html";
var SW = "index.html";
var WSW = "index.html";
var W = "index.html";
var WWW = "index.html";
var NW = "index.html";
var N = "index.html";


if (NNE == "NNE");
{
window.open(
'page1.html'
);
}
else if (NE === "NE")
{
window.open("page2.html");
}
else if (ENE === "ENE")
{
window.open("page3.html");
}
else if (E === "E")
{
window.open("page4.html");
}

else if (ESE === "ESE")
{
window.open("page5.html");
}
.....
else {
window.open("page5.html");
}
}

我是 JavaScript 新手,所以请耐心等待!

感谢您提供任何提示/解决方案。

干杯

最佳答案

如果您希望当前窗口重定向到新的 url,您可以使用:

window.location.href = "http://www.abc.com.au";

关于javascript - 打开特定页面的 JavaScript 操作(轮盘赌)的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29274687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com