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

unable to get waypoints to trigger

Started by Duc 2 hours ago · 1 replies · 17 views
2 hours 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' });
2 hours ago

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

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
3 101 10 hours ago
Support · by Anna, 3 days ago
2 99 1 day ago
Support · by Justin Young, 1 day ago
1 66 1 day ago
Support · by Duc , 1 week ago
2 101 6 days ago
Support · by Colin Hume, 1 week ago
2 95 6 days ago