简体   繁体   中英

html5 animate canvas with elements already drawn

Can I get some help with animating elements on a canvas? I would like to get the elements already drawn on the canvas and "move" them off the canvas and display the new elements. My functions are in javascript and work nicely. I would just like to add animation. TIA.

just have an event handler control the left of the style for that canvas's id and then specify a loop to have it change or move to the left/right based on time.

(function() {
var speed = 10,
movePic = function(moveBy) {
    var el = document.getElementById("animationStyle"),
        left = el.offsetLeft


    if ((moveBy > 0 && left > 399) || (moveBy < 0 && left < 51)) {
        clearTimeout(timer);
        timer = setInterval(function () {
            movePic(moveBy * -1);
        }, speed);
    } 
    el.style.left = left + moveBy + "px";
};
var timer = setInterval(function () {
movePic(3)
}, speed);
}());

This would move it back and forth, this is an example that should help you get started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM