-1

I have an animated menu that functions on the outward but it's stuck on the way back, the first (#section-1) returns perfectly but not other two (#section2, & #section3) sections. Can anybody help me?

$(function() {
    var outTranslate = {
        '-webkit-transform': 'translateX(-100%)',
        '-moz-transform': 'translateX(-100%)',
        '-ms-transform': 'translateX(-100%)',
        '-o-transform': 'translateX(-100%)',
        'transform': 'translateX(-100%)',
        'opacity': '0'
    };

    $("span.menu").click(function() {
        $("#section-1").css(outTranslate, function() {
            setTimeout(function() {
                $("#section-2").css(outTranslate);
            }, 100);
            setTimeout(function() {
                $("#section-3").css(outTranslate);
            }, 200);
            setTimeout(function() {
                $("#menu-overlay").fadeOut(750, 'easeOutQuad');
            }, 300);
        });
    });
});
5
  • 5
    Try to put your code on JsFiddle Commented May 26, 2015 at 13:31
  • 1
    Please show the HTML as well, and clarify what the problem is (what does "stuck on the way back" mean?) Commented May 26, 2015 at 13:32
  • 1
    .css() doesn't have default callback . Commented May 26, 2015 at 13:32
  • 2
    There isn't a .css() method that includes a function callback on completion. This would be obvious if you read the documentation. Commented May 26, 2015 at 13:34
  • Why dont you add a class? Commented May 26, 2015 at 13:36

1 Answer 1

2

You cannot callback function after setting css properties. Because it's not async to have callback. Try this:

$(function() {
    var outTranslate = {
        '-webkit-transform': 'translateX(-100%)',
        '-moz-transform': 'translateX(-100%)',
        '-ms-transform': 'translateX(-100%)',
        '-o-transform': 'translateX(-100%)',
        'transform': 'translateX(-100%)',
        'opacity': '0'
    };

    $("span.menu").click(function() {
        $("#section-1").css(outTranslate);
        setTimeout(function() {$("#section-2").css(outTranslate);}, 100);
        setTimeout(function() {$("#section-3").css(outTranslate);}, 200);
        setTimeout(function() {$("#menu-overlay").fadeOut(750, 'easeOutQuad');}, 300);
    });
});

or this (using transition framework) (link: http://ricostacruz.com/jquery.transit/):

$(function() {
    var outTranslate = {
        '-webkit-transform': 'translateX(-100%)',
        '-moz-transform': 'translateX(-100%)',
        '-ms-transform': 'translateX(-100%)',
        '-o-transform': 'translateX(-100%)',
        'transform': 'translateX(-100%)',
        'opacity': '0'
    };

    $("span.menu").click(function() {
        $("#section-1").transition(outTranslate, function(){
            setTimeout(function() {$("#section-2").css(outTranslate);}, 100);
            setTimeout(function() {$("#section-3").css(outTranslate);}, 200);
            setTimeout(function() {$("#menu-overlay").fadeOut(750, 'easeOutQuad');}, 300);
        });
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, brilliant, functioned perfectly. Thanks so much numßer ! So I didn't need the function on the first (#section-1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.