Skip to content

Instantly share code, notes, and snippets.

@mexitalian
Last active August 29, 2015 14:22
Show Gist options
  • Save mexitalian/f1b98d5289b97b8904ea to your computer and use it in GitHub Desktop.
Save mexitalian/f1b98d5289b97b8904ea to your computer and use it in GitHub Desktop.
mJWqBg
<div id="robot"></div>
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;
}
});
<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>
@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