Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

unable to get waypoints to trigger

Solved by Andy Miller View solution

Started by Duc 4 weeks ago · 3 replies · 340 views
4 weeks ago

I am trying to get this waypoints that is in woo theme (features tab) over to future2021 theme. The effect is the images ballon out and back in when scroll past it. However, I am unable to get it to work fully. I think I have added all the necessary files and css styles as it works when I manually add the classes animated pulseattributes. The jquery is being loaded first before waypoint.js as well.

I think the issue is in the main.js. Woo has it as below and I have paste them over to future theme main.js and changed the necessary classes to match my page. This code may not work over at future theme is what I suspect. The twig file is features.html.twig. It suppose to add classes animated pulse when scroll over the target element (ex: design, responsive, cross-browser, video) within the page.

JS
$('.js .design').waypoint(function() {
$('.js .design .feature-media').addClass( 'animated pulse' );    
}, { offset: 'bottom-in-view' });

$('.js .responsive').waypoint(function() {
$('.js .responsive .feature-media').addClass( 'animated pulse' );    
}, { offset: 'bottom-in-view' });

$('.js .cross-browser').waypoint(function() {
$('.js .cross-browser .feature-media').addClass( 'animated pulse' ); 
}, { offset: 'bottom-in-view' });

$('.js .video').waypoint(function() {
$('.js .video .feature-media').addClass( 'animated pulse' );     
}, { offset: 'bottom-in-view' });
4 weeks ago Solution

Hi Duc,

This has the classic fingerprints of a theme-boilerplate mismatch, and I think the fix is small.

Look at your selectors. They all start with .js:

JAVASCRIPT
$('.js .design').waypoint(...)

That leading .js is a class on the <html> element. The Woo theme (and the Antimatter / HTML5-Boilerplate lineage it comes from) ships a tiny inline head script that rewrites <html class="no-js"> into <html class="js"> the moment JavaScript runs. Future2021 almost certainly does not do this.

If .js never gets added to <html>, then $('.js .design') matches zero elements, so .waypoint() binds to nothing and never fires. That lines up exactly with what you're seeing: the manual animated pulse classes work (they don't depend on .js), but the waypoint-triggered version doesn't.

Quick test. Open devtools and run these in the console on the page:

JAVASCRIPT
document.documentElement.className   // is "js" in there?
$('.js .design').length              // 0 means the selector is dead

If length comes back 0, that's the whole bug. Fixes, easiest first:

  • Drop the .js prefix from the selectors, e.g. $('.design'), or
  • Restore the boilerplate. Either hardcode class="js" on your html tag in the base template, or add the standard no-js to js swap script back into the head. It is a one-liner that sets document.documentElement.className by replacing no-js with js. Modernizr does this for you too if the theme loads it.

If the selector turns out to be fine (length > 0), then check these next:

  1. Waypoints build. The old $(el).waypoint(handler, opts) jQuery syntax needs the jQuery adapter (jquery.waypoints.js). The bare noframework.waypoints.js build does not give you $().waypoint, so the call silently does nothing. If the console shows $(...).waypoint is not a function, that's it.
  2. Offsets measured too early. offset: 'bottom-in-view' is fine, but Waypoints calculates element positions at init time. If your feature images haven't loaded yet, the trigger points are wrong and often never fire. After binding, refresh them on window load with Waypoint.refreshAll().
  3. Check it actually runs. Make sure the code is inside $(document).ready() and that features.html.twig really renders elements with those exact .design, .responsive, etc. classes. Theme migrations often rename the wrapper classes.

My money is on the .js class being missing. Check $('.js .design').length first and let us know what you get.

Cheers

4 weeks ago

Hello. Thank you for the quick reply and hints to my issue. It's working now. Though it would have worked all along if I didn't included a config setting in the main.js without pointing to its .js. I only knew this error when you mentioned the console in the browser devtool. Removing that bit of code or added that .js file fixed the error thus unblocking the waypoints to work properly.

I have added the modernizr.js which auto loads the js class as you have mentioned.

4 weeks ago

@duceduc, As asked before, when a reply solved your issue, please mark it as "solution". Others may benefit from knowing the issue has a solution. The forum works two-way: one takes and gives back...

Thanks

last edited 06/25/26 by pamtbaau

Suggested topics

Topic Participants Replies Views Activity
Support · by Anna, 3 hours ago
0 13 3 hours ago
Support · by Anna, 5 hours ago
0 19 5 hours ago
Support · by David Meissner, 2 weeks ago
11 304 13 hours ago
Support · by Rick Beebe, 2 days ago
3 86 14 hours ago
Support · by BenLaKnet, 2 weeks ago
2 180 16 hours ago