How do I unbind another jQuery function on .click()?

Posted by Mike Barwick on Stack Overflow See other posts from Stack Overflow or by Mike Barwick
Published on 2012-06-26T21:00:22Z Indexed on 2012/06/26 21:15 UTC
Read the original article Hit count: 133

Filed under:
|

I have this script that run to fix my menu bar to the browser on scroll. Nothing really needs to change here (works as it should). However, you may need it...

var div = $('#wizMenuWrap');
var editor = $('#main_wrapper');
var start = $(div).offset().top;

$(function fixedPackage(){   
    $.event.add(window, "scroll", function() {
        var p = $(window).scrollTop();
        $(div).css('position',((p)>start) ? 'fixed' : 'static');
        $(div).css('top',((p)>start) ? '0px' : '');

        //Adds TOP margin to #main_wrapper (required)
        $(editor).css('position',((p)>start) ? 'relative' : 'static');
        $(editor).css('top',((p)>start) ? '88px' : '');
    }); 
});

Now for the issue at hand. I have another script function that calls a modal pop-up (which again works as it should). However, it's not slick from a UI perspective when I scroll the page when the modals open. So I want to disable the script above when the modal script below is called. In other words, when I click to open the modal pop-up, the script above shouldn't work.

$(function () {

var setUp = $('.setupButton');

// SHOWS SPECIFIED VIEW

$(setUp).click(function () {        
    $('#setupPanel').modal('show');
    //PREVENTS PACKAGE SELECT FIXED POSITION ON SCROLL
    $(setUp).unbind('click',fixedPackage);
});

})

As you can see above, I tried to unbind the scroll function (the first code snippet), but this is not correct.

These two scripts are in two separate js libraries.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery