【发布时间】:2016-02-14 05:52:52
【问题描述】:
我正在将 Bootstrap 模板转换为 WordPress 主题,我的所有样式表和脚本都在 functions.php 中引用,在 footer.php 中有一些初始化代码,但有一个特别的未正确执行的文件:http://blackrockdigital.github.io/startbootstrap-creative/js/creative.js.
脚本:
(function($) {
"use strict"; // Start of use strict
// jQuery for page scrolling feature - requires jQuery Easing plugin
$('a.page-scroll').bind('click', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: ($($anchor.attr('href')).offset().top - 50)
}, 1250, 'easeInOutExpo');
event.preventDefault();
});
// Highlight the top nav as scrolling occurs
$('body').scrollspy({
target: '.navbar-fixed-top',
offset: 51
})
// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
$('.navbar-toggle:visible').click();
});
// Fit Text Plugin for Main Header
$("h1").fitText(
1.2, {
minFontSize: '35px',
maxFontSize: '65px'
}
);
// Offset for Main Navigation
$('#mainNav').affix({
offset: {
top: 100
}
})
// Initialize WOW.js Scrolling Animations
new WOW().init();
})(jQuery); // End of use strict
我已将此特定文件设置为使用 jQuery,并通过 functions.php 在 </body> 标记之前调用,但其中没有任何脚本正在执行并且 Chrome 正在返回此错误:
Uncaught TypeError: $(...).scrollspy is not a function
我尝试将$ 别名替换为jQuery,但没有效果。我还确认这是在 jQuery 库之后调用的。
任何帮助将不胜感激。谢谢!
【问题讨论】:
-
尝试在页面底部加载此脚本?我可以在最后加载的原始主题中看到它。尝试引导后加载?
标签: javascript jquery wordpress wordpress-theming