嗨,我有一个onclick按钮方案,已经简化了。我有两个画布(一个正方形和一个圆圈)和一个onclick。单击onclick时...

1)方形画布的饱和度应在3秒后增加5%。

2)3秒钟后会打开一个模态对话框,里面有一个onclick

当按下“模态对话框” onclick时,它会关闭并清除并在旧画布上重新绘制一个新的圆形画布。

理想情况下,总的来说,当黄色正方形的饱和度为25%(或按下按钮5次)时,学习场景应完成并将我发送至404。但是正方形画布不会增加其饱和度,因此我不因为它不会增加到25%,所以不知道它是否会将我发送到404。

但是,这些都不在我的代码中起作用。谁能帮忙。随意问任何问题。



var squaretime = document.getElementById("timeCanvas");
  var sqt= squaretime.getContext("2d");
  sqt.globalAlpha = 0.1;
  sqt.beginPath();
  sqt.rect(0, 0, 80, 80);
  sqt.fillStyle = "yellow";
  //cir.globalAlpha = 0.4;
  sqt.fill();
  sqt.stroke();

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(300, 300, 250, 0, 2 * Math.PI);
ctx.stroke();

ctx.beginPath();
ctx.moveTo(125,125);
ctx.lineTo(475,475);
ctx.stroke();
ctx.beginPath();

ctx.moveTo(125,475);
ctx.lineTo(475, 125);
ctx.stroke();


var modal = document.querySelector(".modal");
var trigger = document.querySelector(".trigger");
var closeButton = document.querySelector(".close-button");


function toggleModal() {
    setTimeout(function() {
        modal.classList.toggle("show-modal");
    }, 3000)
}

function closeModalNow() {
  modal.classList.toggle("show-modal");
  document.querySelector('input[name="conf1d3nce"]').value = null;

var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 600, 600);

ctx.beginPath();
ctx.moveTo(125,125);
ctx.lineTo(475,475);
ctx.stroke();
ctx.beginPath();

ctx.moveTo(125,475);
ctx.lineTo(475, 125);
ctx.stroke();
}

trigger.addEventListener("click", toggleModal);
closeButton.addEventListener("click", closeModalNow);

//increases the yellow square by 5%
   submit = function() {
     reset;

reset = function() {
    check_time()
    var y = document.getElementById("timeCanvas")
    var context = y.getContext('2d');
    context.clearRect(0, 0, y.width, y.height);

    //var squaretime = document.getElementById("timeCanvas");
    var sqt= y.getContext("2d");
    console.log(sqt.globalAlpha)
    check_time()
    sqt.globalAlpha = sqt.globalAlpha + 0.05;
    setTimeout(function() {
    sqt.beginPath();
    sqt.rect(0, 0, 80, 80);
    sqt.fillStyle = 'yellow';
    sqt.fill();
    sqt.stroke();
}, 3000)
}}

//finished the task at 95% saturation of yellow square
check_time = function() {
 var y = document.getElementById("timeCanvas")
  var sqt= y.getContext("2d");
 if (sqt.globalAlpha >= 0.95) {
 console.log(sqt.globalAlpha);
   window.location.href = "INTERCEPT";
 }
}

 .modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.01);
    opacity: 0;
    visibility: hidden;
    transform: scale(1.1);
    transition: visibility 0s linear 0.25s, opacity 0.25s 0s, transform 0.25s;
}
.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 1rem 1.5rem;
    width: 24rem;
    border-radius: 0.5rem;
}
.close-button {
    float: right;
    width: 1.5rem;
    line-height: 1.5rem;
    text-align: center;
    cursor: pointer;
    border-radius: 0.25rem;
    background-color: lightgray;
}
.close-button:hover {
    background-color: darkgray;
}
.show-modal {
    opacity: 1;
    visibility: visible;
    transform: scale(1.0);
    transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s;
}

<div class="styling">
<div class="general_text_2">
<p>Time left </p>
<canvas id="timeCanvas" width="80" height="80" style="border:1px solid #d3d3d3;">
</canvas>

<button class="trigger">Click here </button>
<div class="modal">
    <div class="modal-content">

        <h1>
          <label><b>Please state your confidence with this decision (0-100%)</b></label>
          <p>
         <input class="bottomaftertrialquestions" type="number" placeholder="Type here" name="conf1d3nce"min="0" max="100" required>
          </p>
          <p></h1>
            <button type="button" class="close-button">SAVE</button>
    </div>
</div>


// CIRCLE GRID (MAP)

<canvas id="myCanvas" width="600" height="600" style="border 12px solid black">
</canvas> 

最佳答案

您似乎从未在这段代码中调用submit函数

关于javascript - onClick问题的多种功能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60658642/

10-13 04:37