Affix在Bootstrap 4(alpha)中不起作用 [英] Affix is not working in Bootstrap 4 (alpha)

查看:143
本文介绍了Affix在Bootstrap 4(alpha)中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Bootstrap 3文档,我已将以下属性添加到导航栏:

According to Bootstrap 3 docs I have added following attributes to a navbar:

<nav class="navbar no-margin-bottom" data-spy="affix" data-offset-top="90" >
...
</nav>

向下滚动页面后Bootstrap 4不会将类添加到附加的navbar。谁能告诉我如何解决这个问题? Bootstrap.js和jQuery.js正在工作。

After scrolling down the page Bootstrap 4 is not adding class to navbar which is affix. Can anyone tell me how to solve this problem? Bootstrap.js and jQuery.js are working.

推荐答案

虽然在版本4中从Bootstrap中删除了词缀。但是,你可以通过这个jQuery代码实现你的目标:

Although the affix is removed from Bootstrap in version 4. However, you can achieve your goal through this jQuery Code:

$(window).on('scroll', function(event) {
    var scrollValue = $(window).scrollTop();
    if (scrollValue == settings.scrollTopPx || scrollValue > 70) {
         $('.navbar').addClass('fixed-top');
    } 
});

这篇关于Affix在Bootstrap 4(alpha)中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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