JSFiddle - React, Tailwind, and code Playground
by evg_
HTML
<button class="btn">Старт</button>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
height: 100vh;
}
.btn {
margin: auto;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
padding: 0 10px;
cursor: pointer;
background: lightgreen;
color: #fff;
font-family: "Open Sans";
text-transform: uppercase;
font-size: 14px;
display: block;
border: none;
}
.btn:focus {
outline: none;
}
.modifier {
background: tomato;
}
JavaScript
var btn = document.querySelector(".btn")
isStart = false;
btn.addEventListener("click", function() {
if (isStart) {
btn.classList.remove("modifier");
btn.textContent = "Старт";
isStart = false;
stop();
return;
};
btn.classList.add("modifier");
btn.textContent = "Стоп";
isStart = true;
start();
});
function start() {
console.log("start");
}
function stop() {
console.log("stop");
}