I start an animation by calling the animate method. Now I want to display "done" right after that animation completes, but the callback function doesn't execute, and I don't get how I can do so.
document.addEventListener('DOMContentLoaded', function (event) {
let sliderWrapper = document.getElementsByClassName('slider-wrapper')[0];
class Image {
sliderWrapper = document.getElementsByClassName('slider-wrapper')[0];
constructor(_src) {
this.src = _src;
this.width = `${window.getComputedStyle(sliderWrapper).width}`;
this.move();
}
}
Image.prototype.move = function () {
let img = document.createElement('img');
img.setAttribute("src", this.src);
img.setAttribute("width", this.width);
img.classList.add('img');
sliderWrapper.appendChild(img);
img.animate({
left: 0
}, 1000, function () {
console.log('done')
});
}
let img = new Image('https://via.placeholder.com/150');
});
*{
padding: 0;
margin: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.slider-wrapper{
position: relative;
max-width: 60%;
height: 350px;
margin: 70px auto;
border: 1px solid #000;
}
.img{
position: absolute;
left: 100%;
top: 0;
}
<div class="slider-wrapper">
</div>