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

Lazyload and isotope #51

Closed
gablabelle opened this issue Aug 20, 2012 · 11 comments
Closed

Lazyload and isotope #51

gablabelle opened this issue Aug 20, 2012 · 11 comments

Comments

@gablabelle
Copy link

OK I'm building a new portfolio for myself at http://www.gablabelle.com/ and I'm using your lazyload plugin with isotope to showcase my images. It works great when I scroll down the page but it seems like the images don't show up when filtering without having previously scrolled down. If i scroll down nothing happens.

It's acting like it doesn't consider the images to actually be in viewport (because of isotope).

If I put a high number to failure_limit (like 100 or 1000) it will actually show the images after filtering if I scroll a bit.

Is there something I can do to solve this?

Many thanks.

@benjaminsehl
Copy link

Depending on how you're issuing your filters, you may wish to trigger a +1 & -1 scroll with jQuery on filter click.

@gablabelle
Copy link
Author

@Whoisbenjamin I'm already animating


    $("ul.menu a[href*=category]").click(function(event) {
        event.preventDefault();
        var cat = $(this).parent().attr("class");
        $container.isotope({ filter: "."+cat });
        $("ul.menu a").removeClass("active");
        $(this).addClass("active");
        setTimeout(function() {
            $("html, body").stop().animate({
                scrollTop: 0
            }, 1000);
        }, 100);
        return false;
    });

But it doesn't work only if the page is already at Top position.

@benjaminsehl
Copy link

Feel free to use the simple little function I created:

function forceLoad(){
$.scrollTo('+=1px');
$.scrollTo('-=1px');
}

May not be graceful, but get's the job done and not a hog.

@gablabelle
Copy link
Author

Thanks ... OK if I use the following :

    function forceLoad(){
                alert('function ok');
        $.scrollTo('+=1px');
        $.scrollTo('-=1px');
    };
    $("ul.menu a[href*=category]").click(function(event) {
        event.preventDefault();
        var cat = $(this).parent().attr("class");
        $container.isotope({ filter: "."+cat });
        $("ul.menu a").removeClass("active");
        $(this).addClass("active");
        forceLoad();
        setTimeout(function() {
            $("html, body").stop().animate({
                scrollTop: 0
            }, 1000);
        }, 100);
        return false;
    });

It works but if I remove the alert it doesn't work anymore :-/

@gablabelle
Copy link
Author

@Whoisbenjamin This works. THANK YOU!

    function forceLoad(){
        $.scrollTo('+=1px');
        $.scrollTo('-=1px');
    };
    $("ul.menu a[href*=category]").click(function(event) {
        event.preventDefault();
        var cat = $(this).parent().attr("class");
        $container.isotope({ filter: "."+cat });
        $("ul.menu a").removeClass("active");
        $(this).addClass("active");
        setTimeout(function() {
            $("html, body").stop().animate({
                scrollTop: 0
            }, 1000);
            forceLoad();
        }, 100);
        return false;
    });

@gablabelle
Copy link
Author

@Whoisbenjamin Well it only works if the page is still bigger than viewport (so it can actually scroll) :-/

If you try the Corporatif filter menu it won't work because the page can't scroll. Does it make sense?

@benjaminsehl
Copy link

Not sure I understand.

Here is how I implemented it … there is a bulk of extra code in there as I'm doing a sort of inverse :active state for the other filters, and have implemented jQuery BBQ for permalinks.

Hope this helps.

$('#filters_select').change(function(){
            var value = $(this).find(":selected").val();
            if(value == ""){
                $.bbq.pushState('',2);
                $container.isotope({ filter: '*' });            
                updateSelect("All Categories");
                $("#menu-work_filters a, #menu-people_filters a").each(function() {
                    $(this).removeClass('current'); 
                    $(this).removeClass('deactivated'); 
                });                     
                return false;               
            }
            else{
                var href = value.replace( /^#/, '' ),
                option = $.deparam( href, true );
                $.bbq.pushState( option );
                var hashOptions = $.deparam.fragment();
                $container.isotope( hashOptions, forceLoad );
                $("#menu-work_filters a, #menu-people_filters a").each(function() {
                    if($(this).attr("href")==value){
                        $(this).addClass('current');
                        $(this).removeClass('deactivated');
                        $("#menu-work_filters a, #menu-people_filters a").not(this).each(function() {
                            $(this).removeClass('current');
                            $(this).addClass('deactivated');
                        });     
                    }
                });
            }
        }); 

@gablabelle
Copy link
Author

OK got it ! I used I setTimout to make sure the scroll would occur before the page becomes smaller than the viewport. Thanks!

@gablabelle
Copy link
Author

Hey @Whoisbenjamin the solution doesn't work in Safari... On your site neither, I just checked.

@tuupola
Copy link
Owner

tuupola commented Aug 21, 2012

Have not tried with isotope but have you tried triggering scroll on window?

 $(window).trigger("scroll");

@gablabelle
Copy link
Author

@tuupola Thanks it works!

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

3 participants