一段时间以来,我一直在尝试使用 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/