Javascript method call with a new value

206 Views Asked by At

I am setting up JavaScript function call on page load:

$('.myMenu').affix({
        offset: {
            top: value
        }
    });

After some user interaction the value getting changed and at the same time I am calling the code above again expecting that affix() will be processing with a new offset value, but it is not, it is still processing with initial value what was on page load.

$(window).resize(function() {
        $('.myMenu').affix({
            offset: {
                top: value
            }
        });
    });

$(document).ready(function() {
        $('.myMenu').affix({
            offset: {
                top: value
            }
        });
    });

Why it is happening? may be some one could explain? The windows resize triggering on windows resize I make sure that by using alert function

I am using affix() that is in the twitter bootstrap 3.0 and also I have the same problem with http://github.com/davist11/jQuery-One-Page-Nav plugin

$('.mainNav').onePageNav({
        currentClass: 'active',
        scrollOffset: offsetValue
    });

onePageNav() not applying a new offsetValue if I do onePageNav() on screen resize like above in case of affix().

1

There are 1 best solutions below

5
On

Most plugins provide separate methods for initial attachment to an element (with initial settings) and subsequent changes to those settings.

The precise methods for the latter depend on how the plugin author wrote the code, and indeed whether changes to settings will even be noticed. If (s)he followed the jQuery UI convention it would be:

$('.myMenu').affix('options', { top: value });

To get a better answer, provide a link to the particular "affix" plugin you're using, or check its documentation.