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

The result of a javascript action (a roulette) to open specific pages

本文关键字:结果 操作 javascript      更新时间:2023-09-26

我将这个轮盘赌的代码用于个人项目。轮盘赌运行良好,但我正在尝试让轮盘赌的结果在同一窗口中打开特定页面。我不知道如何针对结果。例如,如果结果是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";

您可以使用Location.replace()

document.location.replace("http://www.abc.com.au");
function openDestinationResult() {
var $100 = "index.html";
var $200 = "content.html";
...
if ($100=="$100");
{
   window.open(
 'http://www.abc.com.au',
 '_blank' // <- This is what makes it open in a new window.Whether a new tab or window is created, is decided by the browser (setting).
 );
}    

希望这能帮助