Need help with jQuery animate
Check开发者_运维百科 out this jsfiddle http://jsfiddle.net/Y7fEW/.
I'm trying to get the tan div on the left so that when you click it, it slides out, and when you click it again, it slides back in.
Currently when you click it, it slides out, but when you click it again, it slides out again. I followed a tutorial online to get this far, but I can't figure it out.
$('#social').live('click', function() {
var $lefty = $(this);
$lefty.animate({
marginLeft: parseInt($lefty.css('marginLeft'), 2) == 0 ?
$lefty.outerWidth() : 0
});
});
The problem is the parseInt
function call:
use parseInt("...")
instead of parseInt("...", 2)
$lefty.animate({
marginLeft: parseInt($lefty.css('marginLeft')) == 0 ?
(40 - $lefty.outerWidth()) : 0
});
check: http://jsfiddle.net/roberkules/Y7fEW/6/
You could use the slide effect from jQuery UI and just say
$lefty.toggle('slide');
精彩评论