Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面刷新后的引导3粘贴位置_Javascript_Jquery_Css_Twitter Bootstrap - Fatal编程技术网

Javascript 页面刷新后的引导3粘贴位置

Javascript 页面刷新后的引导3粘贴位置,javascript,jquery,css,twitter-bootstrap,Javascript,Jquery,Css,Twitter Bootstrap,我已经配置了一个主要起作用的词缀,如本页所示: 这是我动态更改粘贴偏移的代码: // nav-pills is the class of the <ul> element of the sidebar // #hero-unit is the jumbotron // where to start scrolling from $('.nav-pills').affix( { offset: { top: function() { return $('#hero-unit'

我已经配置了一个主要起作用的词缀,如本页所示:

这是我动态更改粘贴偏移的代码:

// nav-pills is the class of the <ul> element of the sidebar
// #hero-unit is the jumbotron

// where to start scrolling from
$('.nav-pills').affix( {
    offset: { top: function() { return $('#hero-unit').outerHeight(true)+10; } }
});

// after changing from affix-top to affix
$('.nav-pills').on('affixed.bs.affix', function() {
    $('.nav-pills').css("margin-top", function() { return -$('#hero-unit').outerHeight(true)+10; } );
});

// after changing back to from affix to affix-top
$('.nav-pills').on('affixed-top.bs.affix', function() {
    $('.nav-pills').css("margin-top", 0);
});
//导航丸是侧边栏
    元素的类 //英雄单位是巨无霸 //从哪里开始滚动 $('导航丸')。粘贴({ 偏移量:{top:function(){return$('#hero unit')。outerHeight(true)+10;} }); //从粘贴顶部更改为粘贴后 $('.nav-pills').on('attached.bs.attached',function(){ $('.nav-pills').css(“页边空白顶部”,函数(){return-$('#英雄单位').outerHeight(true)+10;}); }); //更改为从粘贴到粘贴顶部后 $('.nav pills').on('attached-top.bs.attached',function(){ $('.nav').css(“页边距顶部”,0); });
问题是,当我向下滚动到
粘贴顶部
已更改为
粘贴
的位置并刷新页面时,加载的粘贴在页面下方的位置会比应该的位置低很多。为什么会发生这种情况?我如何解决它?

好吧,这是一个老问题,但答案会帮助某人:

通过在初始化词缀之前添加事件侦听器,您的问题已得到解决

请参阅Github中的线程

试试这个:

// after changing from affix-top to affix
$('.nav-pills').on('affixed.bs.affix', function() {
    $('.nav-pills').css("margin-top", function() { return -$('#hero-unit').outerHeight(true)+10; } );
});

// after changing back to from affix to affix-top
$('.nav-pills').on('affixed-top.bs.affix', function() {
    $('.nav-pills').css("margin-top", 0);
});
$('.nav-pills').affix( {
    offset: { top: function() { return $('#hero-unit').outerHeight(true)+10; } }
});
好吧,这是一个老问题,但答案会对某人有所帮助:

通过在初始化词缀之前添加事件侦听器,您的问题已得到解决

请参阅Github中的线程

试试这个:

// after changing from affix-top to affix
$('.nav-pills').on('affixed.bs.affix', function() {
    $('.nav-pills').css("margin-top", function() { return -$('#hero-unit').outerHeight(true)+10; } );
});

// after changing back to from affix to affix-top
$('.nav-pills').on('affixed-top.bs.affix', function() {
    $('.nav-pills').css("margin-top", 0);
});
$('.nav-pills').affix( {
    offset: { top: function() { return $('#hero-unit').outerHeight(true)+10; } }
});