<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
// Функ для генерации целого случайного числа
function rand(min, max) {
return Math.round(min + Math.random() * (max - min))
}
// Функция записи примера, его решения и вывода ответа
function f1() {
clearTimeout(timeout);
var a = rand(11, 99);
var b = rand(11, 99);
var c = a * b;
var section = document.createElement("section");
section.innerHTML = `
${a} × ${b} = <span class="answer">${c}</span>
<svg>
<circle style="--time: ${speed.value}s;"></circle>
</svg>`;
document.querySelectorAll("section:nth-last-of-type(n + 2)").forEach(element => element.remove())
document.body.appendChild(section);
timeout = setTimeout(f1, (1 + Number(speed.value)) * 1e3);
}
var timeout;
</script>
<style>
body {
background: #111; color: #ccc;
font: 10vmin / 1.5 Helvetica Neue, Segoe UI, Roboto, Ubuntu, sans-serif;
overflow: hidden; display: flex;
flex-direction: column-reverse;
align-items: center;
}
button, select { order: 1; margin: 1em; }
section {
animation: appear 1s ease-out backwards;
padding: 1em; max-width: 10em;
transition: 1s;
position: relative;
}
section:last-of-type { color: deeppink; }
section .answer {
border-bottom: .1em dotted transparent;
}
section:last-of-type .answer {
border-color: gray;
color: transparent;
text-shadow: none;
pointer-events: none;
user-select: none;
}
svg {
width: 5vmin;
height: 5vmin;
transform: rotate(-90deg);
position: absolute;
opacity: 0;
right: 0; top : 42.5%;
transition: 500ms;
}
section:last-of-type svg {
opacity: 1;
}
circle {
fill: none;
r: 2vmin;
cx: 2.5vmin;
cy: 2.5vmin;
stroke-width: .75vmin;
stroke: currentColor;
stroke-linecap: round;
stroke-dasharray: 0 12.6vmin; /* 2π × 2vmin ≈ 12.6vmin */
animation: fillup var(--time) 1s linear forwards;
}
@keyframes fillup {
to {
stroke-dasharray: 12.6vmin 12.6vmin;
}
}
@keyframes appear {
from {
font-size: 0; opacity: 0;
padding: 0; margin: 0;
transform: scale(0);
}
}
label {
font-size: 3.5vmin;
order: 2;
}
input {
font: inherit;
background: none;
color: inherit;
border: 0;
width: 3em;
text-align: center;
}
</style>
</head>
<body>
<label>Следующий пример автоматически через <input type="number" value="5" id="speed"> сек.</label>
<button onclick="f1(); this.textContent = 'Следующий';">Начать</button>
</body>
</html>