3
Opa galera I have a div that is my site header, I want to hide it by clicking a button and make it appear when clicking another button. I can hide and the movement is the way I want, however at the time to make appear back does not have the same fluidity and the image is not on the screen, disappearing at the end.
function myMove() {
var elem = document.getElementById("box-toogle");
var pos = 0;
var t = 0;
var id = setInterval(frame, 5);
function frame() {
if (pos == 160) {
clearInterval(id);
} else {
pos--;
elem.style.top = pos + 'px';
t++;
}
}
function myMove1() {
var elem = document.getElementById("box-toogle");
var pos = 150;
var t = 0;
var id = setInterval(frame, 5);
function frame() {
if (pos == 0) {
clearInterval(id);
} else {
pos--;
elem.style.top = pos + 'px';
t++;
}
}
#box-toogle {
width: 100%;
height: 150px;
position: relative;
}
<html>
<head>
</head>
<body>
<header id="box-toogle">texto</header>
</body>
</html>
I’m a beginner in javascript, if you can help me thank you
looking at your code, the methods
myMove
andmyMove1
doesn’t have the last}
to terminate the method, make the correction and test again.– Brumazzi DB
Their functions are not closed, each one missing a key at the end. I advise using a good IDE for programming, which makes Highlight in the codes and helps you see and perceive these basic errors, Netbeans is one of them.
– Fernando Ferrari
Opa excuse me at the time of copy and paste I ended up forgetting the last key, in my code is closed and still not fluid, I will change the code here glued to agree. I await your opinion thank you.
– VeteranoKuno1