Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Height issues with ajax #31

Closed
gnistdesign opened this issue Sep 10, 2014 · 6 comments
Closed

Height issues with ajax #31

gnistdesign opened this issue Sep 10, 2014 · 6 comments

Comments

@gnistdesign
Copy link

Hi,

I'm using matchHeight() on a WordPress site, and its working fine on initial render. But I'm using Ajax Load More to load more posts, using jQuery's ajaxComplete() to update the height on loaded posts. It's working fine on the first load, but on the second load the heights are set to high (should be around 300px, gets set to around 500px).

Here is my JS:

    jQuery.noConflict();
    jQuery(document).ready(function($){

        $(function() {
            $('#employees .person').matchHeight();
        });

        $( document ).ajaxComplete(function() {
            $.fn.matchHeight._apply('#employees .person')
            $.fn.matchHeight._maintainScroll = true;
        }); 

    });

And ideas?

@liabru
Copy link
Owner

liabru commented Sep 10, 2014

I think you're maybe better doing something more like:

jQuery(document).ready(function($){

    $(function() {
        $.fn.matchHeight._maintainScroll = true;
        $('#employees .person').matchHeight();
    });

    $( document ).ajaxComplete(function() {
        $('#employees .person')
            .matchHeight('remove')
            .matchHeight();
    }); 

});

Does that help?

@gnistdesign
Copy link
Author

Alas, no – that didn't help.

After much trying, the best I've been able to come up with is this:

       $( document ).ajaxComplete(function() {
            $.when('AjaxLoadMore.loadPosts').done(function() {
                setTimeout(function() {
                    $.fn.matchHeight._apply('#employees .person');
                }, 300);
            });
        }); 

ALM uses a slide (or fade) effect that takes 300 ms. If I don't put in the delay, the heights are set way to high. And the page «jumps» when heights are set, no matter if I have the delay or not.

@liabru
Copy link
Owner

liabru commented Sep 16, 2014

Are you saying it works correctly if you apply after the animation is done?
Because that's what I'd expect you'd need to do really.

In terms of the jumping, do you mean _maintainScroll doesn't help at all?
A jsfiddle or link would be useful if you could provide one

@liabru
Copy link
Owner

liabru commented Nov 9, 2014

Closing as I assume you have solved the issue. If not please comment and I will reopen, thanks.

@liabru liabru closed this as completed Nov 9, 2014
@apmeyer
Copy link

apmeyer commented Nov 10, 2016

I can confirm that the initial recommendation above from @liabru works well with the WordPress Plugin Ajax Load More almComplete callback. Thank you for that tip!

@pierre-r
Copy link

pierre-r commented Jun 21, 2021

Hello,

It is not the first time I am confronted to this issue.
If, like me, you are using the Data API, $.fn.matchHeight._update(); doesn't seem to work for some reasons.
Instead, I am calling $.fn.matchHeight._applyDataApi();

Here is an exemple :

// statechangecomplete is the event I trigger when AJAX call has successfully ended
$(window).on('load statechangecomplete', function () {
    $.fn.matchHeight._applyDataApi();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants