开发者

Need help with jQuery animate

开发者 https://www.devze.com 2023-03-13 03:18 出处:网络
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

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消