Professional Documents
Culture Documents
5. Add a function
Open script.js file and then copy the codes shown on the screenshot inside $(document).ready()method.
To explain
the code, once you have already included Waypoints jQuery plug-in, you can now have access to
its global Waypoint class and methods.
As shown in line 25, the targeted element is element with id homeand then inside the waypoint
method we pass what we call an options object.
In line 26, we set the function for the handler property.
Note:
An options object is an object passed into a method which provides configuration information.
A handler property is where you have to indicate the function to be triggered when the top of the selected
element hits the top of the viewport.
6. Another way of using Waypoint function is by declaring an instance of Waypoint class. Look at the
screenshot as an example.
The screenshot is the same as the function we made earlier but is written in a different format.
In this format, element andhandler properties are REQUIRED to be set in passing an options object.
The role of the element property is that it selects the element to be observed during scroll.
The Offset Property
For the purpose of this activity, let us explore what an offset property does.
Add the highlighted code in the Waypoint method.
7. In this example, the function is going to be triggered when the element is 10px from the top.
(Save and run the website to see)
An offset property takes any value to trigger the function N pixels away from the selected element.