I'm working on a div
section and I want it to come down and rotate when a button is clicked. However, after moving to the bottom, it doesn't rotate as expected but instead returns to its initial position along the Y axis. How can I fix this issue?
let slider = document.getElementsByClassName('slideshow')[0];
function moveFunction() {
slider.classList.add('movement');
setTimeout(nextFunction, 5000);
}
function nextFunction() {
slider.removeAttribute('class', 'movement');
slider.classList.add('movementAfter');
}
* {
padding: 0;
margin: 0;
}
body {
background-image: url('346767.jpg');
background-size: cover;
z-index: 0;
}
#colorbody {
background-color: rgba(235, 107, 107, 0.425);
position: absolute;
z-index: 1;
width: 100%;
height: 100%;
}
.slideshow {
height: 100px;
width: 200px;
background-color: rgb(68, 0, 255);
margin: 0 auto;
}
.movement {
transform: translateY(500px);
transition: 4s;
}
.movementAfter {
transform: rotate(360deg);
background-color: red;
transition: 2s;
margin: 0 auto;
height: 100px;
width: 200px;
}
<div class="slideshow" class="movement"></div>
<button id="chos" onclick="moveFunction()">Click to Move</button>