Ho un sito dove desidero 'navigazione secondaria'. Quindi, quando si scorre verso la sezione, la relativa barra degli strumenti verrà apposta sotto la barra degli strumenti principale. Ho questo funzionamento, ma non posso cambiare l'offset superiore dopo l'inizializzazione. La documentazione dicono:Cambio bootstrap di Twitter offset affisso
affix('refresh')
When using affix in conjunction with adding or removing of elements from the DOM, you'll want to call the refresh method:
ma quando provo questo ottengo:
Uncaught TypeError: Object # has no method 'refresh'
Ecco il mio codice:
$(function() {
$('.sec-nav').addClass("affix-top");
var adjustNavs = function (first) {
$('.sec-nav').each(function(){
var $p = $(this).closest('.sec');
var $$ = $p.prevAll('.sec');
console.log($$);
var h = 0;
$$.each(function() { h+=$(this).outerHeight();});
console.log(h);
if (first) {
$(this).affix({offset: {top: h}});
} else {
$(this).data('affix', {b: {options: {offset:{top: h}}}});
console.log(this);
$(this).affix('refresh')
}
});
}
adjustNavs(true);
$('.sec').bind('DOMSubtreeModified', function() {
adjustNavs();
});
});
ho provato diverse variazioni di
$(this).data('affix', {b: {options: {offset:{top: h}}}});
compresi:
$(this).affix({offset: {top: h}});
Non riesco a modificare lo scostamento. Come modifichi l'offset del plugin affisso? Grazie.
Si può incollare un blocco dell'HTML? Abbastanza difficile da dire altrimenti ... Se provate a sostituire '$ ('. Sec-nav'). AddClass (" affix-top ");' con '$ ('. Sec-nav'). Affix();' questo non aiuta affatto? O hai già ottenuto l'attributo 'data-spy =" affix "' su '.sec-nav'? –