Sol sonic keypress animate

De wikiserver
Dreceres ràpides: navegació, cerca
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
        <style>

            img {
                position: relative;
                top:50px;
                left:250px;

            }

        </style> 

        <script>


            $(document).ready(function() {
                $(document).keypress(function(event) {
                    if (event.which == '97') {  //q
                        $('img').animate({top: '+=50px'}, 500);
                    }
                    else if (event.which == 113) {  //a
                        $('img').animate({top: '-=50px'}, 500);
                    }

                });
            });

        </script>
    </head>
    <body>
        <img src="http://i1061.photobucket.com/albums/t480/ericqweinstein/mario.jpg"/>
    </body>
</html>