重置/更改引导词缀的偏移量 [英] Resetting / changing the offset of bootstrap affix

查看:28
本文介绍了重置/更改引导词缀的偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 Affix (Twitter Bootstrap 3) 的偏移量更改为其他值?

How do I change the offset of Affix (Twitter Bootstrap 3) to another value?

当我尝试像这样调用该方法两次时,第二次似乎被忽略并且没有任何效果:

When I tried to call the method twice like this, the second one seems to be ignored and does not have any effect:

$('#navbar-main').affix({ offset: 100});
$('#navbar-main').affix({ offset: 200}); // ---> the offset will not change to 200px

在第二次调用 affix 之前重置 .affix 回调也没有帮助:

Resetting the .affix callback before calling affix the second time didn't help either:

$('#navbar-main').affix({ offset: 100});
$(window).off('.affix');
$('#navbar-main').affix({ offset: 200}); // ---> the offset will not change to 200px

推荐答案

这是方法.关键是在 .affix 上调用 off,并且在附加元素上调用 removeData.假设我想重置 #navbar-main 的词缀:

Here's how. The key is to both call off on .affix, and also, removeData on the affix'ed element. Let's say I want to reset the affix of #navbar-main:

引导程序

3(来自 es128):

$(window).off('.affix')
$('#navbar-main').removeData('affix').removeClass('affix affix-top affix-bottom')
$('#navbar-main').affix({ offset: 400})

Bootstrap 3(来自 Dysko):

Bootstrap 3 (from Dysko):

$(window).off('.affix')
$('#navbar-main').removeData('bs.affix').removeClass('affix affix-top affix-bottom')
$('#navbar-main').affix({ offset: 400})

这篇关于重置/更改引导词缀的偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆