Also habe ich drei Tasten, jeder löst ein Ereignis aus. Gleichzeitig mit dem Auslösen eines Ereignisses möchte ich, dass es neben der angeklickten Schaltfläche ein Div verschiebt. Problem ist, dass ich möchte, dass ich nicht neben der Schaltfläche teleportiere, sondern mich in einer Animation dorthin bewege. Ich habe meinen Code wie unten gezeigt organisiert, aber es passiert nur einmal und wenn ich dann versuche auf einen anderen Button zu klicken, bleibt das Div dort.Haben Knöpfe bewegen div verschiedene Mengen
function func1() {
var elem = document.getElementById("thebarofpower");
var pos = elem.style.top;
var doneTheStuff;
var id = setInterval(frame, 10);
function frame() {
if (!doneTheStuff) {
doneTheStuff = true;
} else if (pos == 6) {
clearInterval(id);
} else if (pos > 6) {
pos++;
elem.style.top = pos - 'px';
} else {
pos++;
elem.style.top = pos + 'px';
}
}
}
function func2() {
var elem = document.getElementById("thebarofpower");
var pos = elem.style.top;
var doneTheStuff;
var id2 = setInterval(frame2, 10);
function frame2() {
if (!doneTheStuff) {
doneTheStuff = true;
} else if (pos == 60) {
clearInterval(id2);
} else if (pos > 60) {
pos++;
elem.style.top = pos - 'px';
} else {
pos++;
elem.style.top = pos + 'px';
}
}
}
function func3() {
var elem = document.getElementById("thebarofpower");
var pos = elem.style.top;
var doneTheStuff;
var id3 = setInterval(frame3, 10);
function frame3() {
if (!doneTheStuff) {
doneTheStuff = true;
} else if (pos == 120) {
clearInterval(id3);
} else {
pos++;
elem.style.top = pos + 'px';
}
}
}
#button-1 {
position: absolute;
background: transparent;
left: 0px;
top: 0px;
width: 50px;
height: 50px;
border: ;
box-shadow: 6px 6px 6px #888888;
}
#button-2 {
position: absolute;
background: transparent;
left: 0px;
top: 60px;
width: 50px;
height: 50px;
border: ;
box-shadow: 6px 6px 6px #888888;
}
#button-3 {
position: absolute;
background: transparent;
left: 0px;
top: 120px;
width: 50px;
height: 50px;
border: ;
box-shadow: 6px 6px 6px #888888;
}
#thebarofpower{
position: absolute;
background-color: #42bff4;
width: 2px;
height: 50px;
left: 70px;
top: 0px;
border-radius: 30px;
box-shadow: 0px 0px 10px 1px #41d0f4;
}
<button id="button-1" onclick="func1()"></button>
<button id="button-2" onclick="func2()"></button>
<button id="button-3" onclick="func3()"></button>
<div id="thebarofpower"></div>
Sehr elegant, aber OP sagt nichts über jquery ... – larz
und das ist teleporting, ich es nicht – TechEndling
glatt bearbeiten jetzt, es prüft jetzt –