Waypoints.js waypoint is not a function

我们两清 提交于 2020-07-03 13:40:06

问题


I'm getting the console error:

Uncaught TypeError: $(...).waypoint is not a function

FYI: It is a Blogger template, which uses XML.

I have included the files like so (only these two .js files):

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/noframework.waypoints.min.js'/>

My jQuery (longer scripts removed for clarity):

<script>
  // <![CDATA[
    $.noConflict();
    jQuery( document ).ready(function( $ ) {
      <!-- LET'S ADD SPAN ELEMENT TO WIDGET HEADINGS SO WE CAN DO ACCESSIBILITY & INCLUSIVE DESIGN -->
      $('.widget > .title').each(function() { $(this).wrapInner('<span />'); });
      <!-- LET'S ADD A CLASS TO THE MAIN MENU WHEN SCROLLING DOWN PAST THE MAIN HEADER -->
      $("#main-header").waypoint(function() { $('#main-menu').addClass('hide'); }, { offset: '100%' });
      <!-- LET'S MAKE THE PAGE LOADER GO AWAY WHEN PAGE IS LOADED  -->
      $('#page-loading-cover').delay(1500).addClass('page-loaded');
    });
  // ]]>
</script>

Why is it not working, and how do I fix it?


回答1:


You added the stand-alone library (waypoint — notice the noframework part), not the jQuery plugin (jquery-waypoints). See this CDN list and pick https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js, i.e. include

<script src='https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/jquery.waypoints.min.js'/>

instead of

<script src='https://cdnjs.cloudflare.com/ajax/libs/waypoints/4.0.1/noframework.waypoints.min.js'/>


来源:https://stackoverflow.com/questions/62418727/waypoints-js-waypoint-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!