A Pen by Giovanni Carlo Marasco on CodePen.
Last active
August 29, 2015 14:22
-
-
Save mexitalian/f1b98d5289b97b8904ea to your computer and use it in GitHub Desktop.
mJWqBg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="robot"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $robot = $('#robot'), | |
transEnd = 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', | |
left = 37, | |
right = 39, | |
a = 97, | |
s = 115, | |
stepSprite = function() { | |
$robot.velocity({ | |
opacity: 0, | |
backgroundPosition: '-1600px 0px' | |
},{ | |
loop: 2, | |
duration: 1000 | |
}); | |
}; | |
$robot.on('click', function() { | |
$(this).velocity({ marginLeft: '+=100px' },{ duration: 1000 }); | |
}); | |
$(document).on('keypress', function(ev) { | |
var keyCode = ev.keyCode || ev.which; | |
switch (keyCode) { | |
case a: | |
var src = $robot.css('background-image').split('(').pop().slice(0,-1), | |
img = new Image().src = src; | |
alert( img.width ); | |
break; | |
case s: | |
// alert('right'); | |
stepSprite(); | |
break; | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.2/velocity.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@img_root: "http://charlos.co.uk/exp/"; | |
#robot { | |
width: 400px; | |
height: 600px; | |
background-image: url("@{img_root}robot_walk_sprite.png"); | |
background-position: 0px 0; | |
/*transition: 0.5s; | |
transition-timing-function: steps(4,end); | |
&.walk { | |
background-position: -1600px 0; | |
} */ | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment