2
I’m having problems with this Script, initially the purpose of it is just to show the controls while the mouse moves or clicks on the div, and when it stops moving it hides the controls after a while, it works normally, but after a few more uses it starts bugging and do not know how to solve, I am using it to hide the controls of a player, below I made a small example of how I am using, if anyone can help me, would be grateful!
function inicializacao() {
player = document.getElementById("player");
controles = player.querySelector(".controles");
player.addEventListener("mousemove", controle, false);
player.addEventListener("mousedown", controle, false);
player.addEventListener("keydown", controle, false);
}
window.onload = inicializacao;
function controle(event) {
var tempoContado = setTimeout(Off, 3000);
On();
function On() {
controles.style.bottom = "0px";
clearTimeout(tempoContado);
tempoContado = setTimeout(Off, 3000);
}
function Off() {
controles.style.bottom = "-50px";
}
}
#player,
#player * {
padding: 0px;
margin: 0px;
}
#player {
background: yellow;
position: relative!important;
height: 50px;
width: 400px;
}
.controles {
background: red;
position: absolute;
height: 50px;
width: 100%;
bottom: 0;
left: 0;
}
<div id="player">
<div class="controles"></div>
</div>
"but after a few more uses it starts bugging" - how specifically ? I tried to reproduce the problem but unsuccessfully
– Isac
Like, when the mouse starts to move at the beginning it works normally, so I leave the mouse standing over it until it hides the control, and then when it moves the mouse again the control goes back and forth without stopping
– João Victor
When you leave the mouse on it, it disappears after a while and after it appears again, it barely moves again disappears again because the mouse is already over that area. Wasn’t that what was supposed to happen ? What working did you intend to get ?
– Isac
Don’t use jQuery? It’s much better for these kinds of things.
– Sam
I’m trying to avoid using jquery, I’m trying to use this to hide the controls of a video player when not the mouse activity in that area and show again when it moves again
– João Victor
Charging 84Kb to make your life easier I think it doesn’t come out expensive. But if you want to use pure, quiet JS.
– Sam
This script I tried to do I used a base made in jquey kkk, only thing I changed was the $("#player"). Mousemove(onEvent); and put player.addeventlistener("Mousemove", control, false);
– João Victor