Reputation: 19294
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
});
});
Upvotes: 0
Views: 307
Reputation: 69905
You could use the slide effect from jQuery UI and just say
$lefty.toggle('slide');
Upvotes: 0
Reputation: 6605
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/
Upvotes: 1