问题
I am just starting out with Waypoints in a site I want to create.
For test purposes, I created a page with 4 colored divs. I want to test if waypoints fires a function when I scroll to the second div.
However the console spits an error: Uncaught ReferenceError: Waypoint is not defined
HTML:
<!DOCTYPE html>
<html>
<head>
<script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script data-require="waypoints@2.0.4" data-semver="2.0.4" src="//cdnjs.cloudflare.com/ajax/libs/waypoints/2.0.4/waypoints.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<div id="four"></div>
</body>
</html>
CSS:
#one{
background-color:red;
// width:100%;
height:400px;
}
#two{
background-color:blue;
float:clear;
height:400px;
}
#three{
background-color:green;
height:400px;
}
#four{
background-color:yellow;
height:400px;
}
JQUERY/WAYPOINTS:
var waypoint = new Waypoint({
element: document.getElementById('#two'),
handler: function(direction) {
alert('I am 20px from the top of the window');
},
});
Here is a link to plunker.
回答1:
You are requiring Waypoints version 2.0.4 but using it in a way that only works with Waypoints 3.0+. Upgrade to the latest version.
来源:https://stackoverflow.com/questions/31967623/waypoint-function-undefined