0

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().

Sergino
  • 10,128
  • 30
  • 98
  • 159

1 Answers1

1

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.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • Should it be `$('.myMenu').affix('options', { offset: { top: value } });` ? – Sergino Dec 24 '13 at 23:07
  • @sreginogemoh no, the bad news is that the Bootstrap affix plugin doesn't have an API method to change the options. For a nasty hack you can potentially alter `$(element).data('bs.affix').options.offset` – Alnitak Dec 24 '13 at 23:11
  • and what abut `http://github.com/davist11/jQuery-One-Page-Nav` does it have the API to change options? – Sergino Dec 24 '13 at 23:17
  • trying to `$('.myMenu').data('bs.affix').options.offset = value` - getting error `Uncaught TypeError: Cannot read property 'options' of undefined ` – Sergino Dec 24 '13 at 23:21
  • Well, I did say _potentially_, based on a quick reading of the source code. – Alnitak Dec 24 '13 at 23:25