Сообщение от pokk
|
независимое и синхронное мигание текста двух div
|
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.BlinkText{
width: 100px;
height: 100px;
background-color: #0000CD;
color: #FFFFFF;
text-align: center;
line-height: 100px;
transition: .5s;
}
.BlinkText.disable{
background-color: #F0E68C;
color: #FF0000;
}
</style>
</head>
<body>
<div class="BlinkText">1</div>
<div class="BlinkText">2</div>
<button class="BlinkText">click 1</button>
<button class="BlinkText">click 2</button>
<script>
let DivsBlinkText = [...document.querySelectorAll("div.BlinkText")],
ButtonsBlinkText = [...document.querySelectorAll("button.BlinkText")],
opacity = 1;
ButtonsBlinkText.forEach((button, i) => {
DivsBlinkText[i].timer ^= 1;
button.addEventListener("click", () => {
DivsBlinkText[i].timer ^= 1;
button.classList.toggle("disable")
})
});
(function timer()
{ opacity ^= 1;
for (let div of DivsBlinkText) {
div.style.opacity = div.timer ? opacity : 1;
}
window.setTimeout(timer, 500)
})()
</script>
</body>
</html>