繁体   English   中英

无法在自定义WordPress主题中运行JS文件

[英]Unable to run JS file in custom WordPress theme

我正在将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库之后会调用此函数。

任何帮助将非常感激。 谢谢!

我认为您忘记链接bootstrap.min.js或正确链接它

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM