jquery - 词缀不是函数

标签 jquery css wordpress twitter-bootstrap

一段时间以来,我一直在尝试使用 Bootstrap 4 Alpha 在我的 Wordpress 网站上创建一个粘性侧边栏。我在网上发现了与此类似的其他问题,大多数建议将代码放在

jQuery(document).ready(function($){
});

我已经试过了,但没有成功。我也尝试过重新安排我的脚本的调用顺序,但也没有用。

这是我目前拥有的基本 Bootstrap 边栏代码

jQuery(document).ready(function($){
$('#sidebar').affix({
      offset: {
        top: 245
      }
});

var $body   = $(document.body);
var navHeight = $('.navbar').outerHeight(true) + 10;

$body.scrollspy({
    target: '#leftCol',
    offset: navHeight
});
});

这是错误信息

Uncaught TypeError: $(...).affix is not a function

有没有人碰巧知道为什么会出现这个问题?

谢谢

最佳答案

Affix 已从 Bootstrap 版本 4 中删除。 Bootstrap 4 documentation says --

Dropped the Affix jQuery plugin. We recommend using a position: sticky polyfill instead. See the HTML5 Please entry for details and specific polyfill recommendations.

If you were using Affix to apply additional, non-position styles, the polyfills might not support your use case. One option for such uses is the third-party ScrollPos-Styler library.

补救措施来了---

Take a look at it it should help you to achieve what you want

关于jquery - 词缀不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42238553/

相关文章:

css - Font Awesome 5.8.1 未加载图标

javascript - Jquery - IF-ELSE 逻辑不起作用

jquery - 将单列文本输入重新排列为多列

javascript - Jquery SlideUp,关闭但不显示效果

CSS单选按钮标签选择器

javascript - 我的站点使用 "defer"进行快速加载,但破坏了 Opera Mini 的站点,有什么解决方法吗?

php - WordPress自定义帖子类型管理页面布局

javascript - JQuery,将相同的函数绑定(bind)到 3 个不同的文本框的 keyup 事件

jquery - 将悬停状态更改应用于子元素

html - 横幅图片不会响应地填充容器