SO, Sliding Images

by acbabis

JavaScript

$(function () {
    var images = [
        'http://placehold.it/100x100',
        'http://placehold.it/150x150',
        'http://placehold.it/200x250',
        'http://placehold.it/200x200'];
    var index = 0;
    $(document).on('keypress', function (event) {
        var c = String.fromCharCode(event.charCode);
        if(c === 'a') {
            var image = images[index];
            console.log(image);
            index = (index + 1) % images.length;
            $('<img style="position: fixed; bottom: 0; right: 0" src="' + image + '"/>').appendTo(document.body).animate({right: '200%'}, 2000, function() {
                $(this).remove();
            });
        }
    })
});