2016-02-14 110 views
1

我正在将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库之后调用的。

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

+0

试装车这个脚本在页面的底部?我可以在它在最后被装入原来的主题看。尝试引导后加载? – DpEN

回答

0

我想你忘了链接bootstrap.min.js或正确链接它

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

我有以下functions.php: 'wp_enqueue_script('bootstrap','//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js');' –

+0

@Mario Parra .. 。你在cdn之前尝试http,就像.... http:// mxcdn ... –