2

I'll try explain what I want to do. I have a resize function which runs when I press a button. This function opens two columns out of window and leave it out when the window is resized. However, I would like to reset that handler when I click on another div later. Just remove or clear that function from memory to avoid the resize. I have read some posts but any of them solve my problem.

My function to resize is:

function resizeColumnsOut(){
    $(window).resize(function() {
        var widthLeft = $('.column-left').outerWidth()+100,
            widthRight = $('.column-right').outerWidth()+100,
            vph = $(window).height();
        $('.options').css({'height': vph + 'px', 'overflow': 'hidden'});
        $('.column-left').css(
            {'transform': 'translateX(-'+widthLeft+'px)', 
            'transition': 'all ease-out .6s'});
        $('.column-right').css(
            {'transform': 'translateX('+widthRight+'px)',
            'transition': 'all ease-out .6s'});
    }).resize();
 }

$('[data-menu="close"]').click(function(){
    $(this).hide();
    resizeColumnsOut();
});

My function to reset the previous function when I click on:

function goAbout(){
    $('.about').click(function(){
      /* Events like .off() or .unbind() don't solve my problem since the resizeColumnsOut() function is already running */
    }
2
  • Yes, .off() is the way to go. If you mean that the animation is still running, after doing .off() you need to set transform:none !important and transition with .css(). Commented Jan 29, 2015 at 11:00
  • @Spokey Thanks a lot, problem solved. I needed to play with on() and off() :) Commented Jan 29, 2015 at 11:45

1 Answer 1

4

Use on and off instead:

Turn on with:

$(window).on('resize', function() { [code snipped] });

Turn off with:

$(window).off('resize');

Also you need to abort, or complete, the animations you have started. When you say your resizeColumnsOut function is still running, you actually meant the CSS animations it started are still going :)

Sign up to request clarification or add additional context in comments.

1 Comment

I wasn't on the wrong track then, more or less :) Thank you so much for your time.

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.