1

I am trying to incorporate Parallax.js (jQuery) and Ajax Load More (WordPress plugin) to the same page. When Load More changes the length of the page, the parallax images should re-position themselves with everythig else, but they don't, so I am left with empty spaces where the images should be.

The problem can be seen here – scroll down to 'Past Events'.

I realise that Parallax needs to be re-triggered when the page is re-sized (as per this thread) but I have not managed so far to write the code that will make this happen. Part of the issue may be that I'm using the Ajax Load More WordPress plugin and so don't have the same kind of access to the code as for the Parallax effect (I don't want to edit the plugin files themselves).

I am loading the scripts in the theme files as follows:

<script src="js/jquery-3.3.1.min.js"></script> <script src="js/jquery.parallax.min.js"></script>

and calling the images as follows:

<div class="parallax-img" data-parallax="scroll" data-src="<?php the_field('page_break_1'); ?>" data-bleed="50" data-midnight="mh-clear"></div>

The repeater for the Load More function is simple php which I can share if it is helpful but which seems irrelevant to this function – I'm not sure what the plugin is doing code-wise beyond that.

I am hoping for the absolute positioned elements (parallax scrolling images) to have their positions re-plotted when the page is made longer. How can I write the function that will make this happen please?

1 Answer 1

0

Ajax Load More has callbacks functions that are dispatched after certain events that you can use for this purpose.

For this case, check out the almComplete callback. https://connekthq.com/plugins/ajax-load-more/docs/callback-functions/almcomplete/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks @Darren. It's not clear to me how to implement this though – I've tried adding window.almComplete = function(alm){ $(window).trigger('resize').trigger('scroll'); }; and window.almComplete = function(alm){ jQuery(window).trigger('resize').trigger('scroll'); }; but i'm not seeing any change. How should I be implementing this?
You would implement inside a custom JS file or on the page itself. I suggest testing the function is being hit with a console.log
in the page itself (footer) is where i've done this. the console.log is appearing as expected but still not seeing that picture move? here's what i'm running – maybe you can see where i'm going wrong?: <script> window.almComplete = function(alm){ jQuery(window).trigger('resize').trigger('scroll'); console.log('#almComplete should have fired'); }; </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.