Well I'm putting together a custom button with css. I need to keep it locked for 2 seconds after the first click, but it is not working. When clicking I change the text to an icon, and after 2 seconds the text has to go back and the button has to be released for the click.
Does anyone know what I'm doing wrong?
$(document).ready(function () {
$("button").click(function () {
$(this).html("<i class='material-icons animate-spin'>autorenew</i>");
// Desabilita o botao
$(this).disabled = true;
// Habilita novamente após dois segundos (2000) ms
setTimeout(function () {
toggleDisabled($(this));
}, 2000);
function toggleDisabled(elem) {
elem.disabled = !elem.disabled;
}
});
});
.bt {
transition: all .3s ease-out;
transition-property: all;
transition-duration: 0.3s;
transition-timing-function: ease-out;
border:0;
padding:10px;
width:200px;
height: 50px;
display: inline-block;
margin: 10px;
cursor: pointer;
border-radius: 4px;
background-color: #0091FF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><!--MaterialIcons(Google)--><linkhref="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<button class='bt' type='submit'>OK</button>