Javascript 动态重新计算引导粘贴';jQuery单击事件上的s offset()
在我的应用程序中,我有两个jQuery函数: 第一个管理一个简单的滑动切换:Javascript 动态重新计算引导粘贴';jQuery单击事件上的s offset(),javascript,jquery,twitter-bootstrap,affix,Javascript,Jquery,Twitter Bootstrap,Affix,在我的应用程序中,我有两个jQuery函数: 第一个管理一个简单的滑动切换: $( ".js-support-toggle" ).click(function(e) { e.preventDefault(); $('.filter-weight').toggleClass('open'); $('.filter-weight .dropdown-body').slideToggle(); }); 和相应的标记: <section class="dropdown f
$( ".js-support-toggle" ).click(function(e) {
e.preventDefault();
$('.filter-weight').toggleClass('open');
$('.filter-weight .dropdown-body').slideToggle();
});
和相应的标记:
<section class="dropdown filter-weight">
<a class="dropdown-title js-filter-toggle">Filter</a>
<div class="dropdown-body">
...
</div><!-- /dropdown-body-->
</section>
该偏移量是通过收集粘贴菜单上方每个元素的outerHeight()值来确定的,包括我的滑动切换。筛选权重元素
当.filter weight
元素折叠时,这一切都非常有效。但是,如果用户将其切换打开,然后向下滚动页面,则切换元素的添加高度会影响偏移量计算
如何重写我的offset()以动态调整到我的过滤器权重元素的可变高度
/* Affixes sidebar nav to top of screen */
$('#scrollspy').affix({
offset: {
top: function () {
return (this.top = $('.header-wrapper').outerHeight(true) + $('.filter-weight').outerHeight(true) + $('.secondary-navigation').outerHeight(true) + $('.filter-weight').outerHeight(true) + 100)
},
bottom: function () {
return (this.bottom = $('.footer').outerHeight(true))
}
}
})