I try to do some kind of grid that need to show dot based animation in the future.
But it seams to perform pretty slowly even with a few elements (i need to apply it to maybe 5times that many items)
$('div').bind('shrink', function(){
var $that = $(this).find('> em > span');
$that.animate({'width': '3px', 'height': '3px'}, 500);
}).bind('grow', function(){
var $that = $(this).find('> em > span');
$that.delay(50).animate({'width': '100%', 'height': '100%'}, 300);
}).append('<em><span><span><em/>');
//triggering shrink and grow on hover
before starting to do complex animations i wanted to test it with a hover effect.
you can take a look at the demo here:
http://jsfiddle.net/meo/GvfVb/7/
How could i improve the performance of this script?
I seem to get some performance improvements with this version:
Example: http://jsfiddle.net/patrick_dw/GvfVb/10/
Here are the changes I made:
shrinkandgrowinto named functions, so that.trigger()doesn’t need to be called to fire them, while retaining the ability to remove them by name.mouseenterevent directly on the<span>tag so you don’t need to do a.find()every timemouseenterfires.mouseleaveneeds to be on the<div>so I optimized it by removing the.find()and replacing it with a nativethis.firstChild.firstChild.growfunction to animate thewidthto an absolute value of20pxinstead of100%. Things really smoothed out with that change.You could also probably unbind the
mouseleavewhen you click so that it isn’t firing to no effect after themouseenterhas been unbound.