我正在将Bootstrap模板转换为WordPress主题,并且我已经获得了在functions.php中引用的所有样式表和脚本以及一些初始化代码在footer.php中,但有一个特定的文件不能正确执行:http://blackrockdigital.github.io/startbootstrap-creative/js/creative.js。无法在自定义WordPress主题中运行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库之后调用的。
任何帮助将非常感激。谢谢!
试装车这个脚本在页面的底部?我可以在它在最后被装入原来的主题看。尝试引导后加载? – DpEN