jQuery | How can I modify this, using functions that aren't deprecated?

brsy

nah mang
May 12, 2011
1,530
272
I have this jsFiddle that works perfectly for what I want to do, but it uses deprecated jQuery functions. Can someone lead me in the right direction? I tried using toggle(), but it still didn't work.

 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,484
1,485
Code:
$(function() {
    $('.clickme').click( function() {
        var toggled = $(this).data('toggled')||1
        switch ( toggled ) {
            case 1:
                $("#slideout").animate({left:'0px'}, {queue: false, duration: 500});
                break;
            case 2:
                $("#slideout").animate({left:'-280px'}, {queue: false, duration: 500});
                break;
        }
        toggled++;
        if (toggled > 2) toggled = 1
        $(this).data('toggled',toggled);
    });
});
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,935
3,936
Here's how I'd do it:
Code:
$(function () {
    $('.clickme').on('click', function() {
        $('#slideout').toggleClass('slideout-toggle');
    });
});

Then I'd add the following CSS class:
Code:
#slideout.slideout-toggle {
  left: 0px;
}

Then I'd utilize the (CSS3) on #slideout, by adding:
Code:
    transition: all 0.5s;
    -webkit-transition: all 0.5s;

 

Users who are viewing this thread

Top