Skip to content

Instantly share code, notes, and snippets.

@cgush
Created January 3, 2014 16:45
Show Gist options
  • Select an option

  • Save cgush/8241319 to your computer and use it in GitHub Desktop.

Select an option

Save cgush/8241319 to your computer and use it in GitHub Desktop.
$('#my-div').html('<img src="http://i.imgur.com/90Mmdcm.png">')
$('#my-div img').hover( function() {
this.src = 'http://i.imgur.com/nTj3Fxx.gif'
}, function() {
this.src = 'http://i.imgur.com/90Mmdcm.png'
})
$('#my-div img').mousedown( function() {
this.src = 'http://i.imgur.com/Rfj0a80.png'
})
$('#my-div img').mousedown(function() {
$('.demo-hadouken').remove();
})
$('#my-div img').mousedown(function() {
$('#my-div').append(
'<img class="demo-hadouken" src="http://i.imgur.com/oTyQRvX.gif">'
);
})
$('#my-div img').mousedown(function() {
$('audio')[0].load();
$('audio')[0].play();
$('.demo-hadouken').animate( {
"margin-left": "600px"
}, 1000, 'swing', function() {
this.remove();
});
})
$('#my-div img').mouseup(function() {
this.src = 'http://i.imgur.com/nTj3Fxx.gif'
})
@sta1r
Copy link

sta1r commented Jan 3, 2014

Nice!

@sta1r
Copy link

sta1r commented Apr 3, 2014

By the way, the above can clearly be optimised by caching selectors and combining the mousedown events. See https://gist.github.com/strangerpixel/9961244 or http://cdpn.io/rqIgs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment