twentytwenty icon indicating copy to clipboard operation
twentytwenty copied to clipboard

Not displaying at load but pops up when resizing window

Open CybranM opened this issue 9 years ago • 15 comments

Hi, I'm using twenty twenty but sometimes the images dont show up at all. If I resize the window it pops up and after that it displays correctly. Is there anything I can to do fix this? I've got it inside a div class with width: 100% !important; but that didnt solve the issue.

Anyone got any ideas on how to solve this?

Thanks

Edit: Adding a 1px border seems to have partially solved the issue, if anyone knows something better it would be nice.

Edit 2: Nvm, adding a 1px border doesn't work all the time. It randomly chooses to not work. It works in in IE and FF but not chrome.

CybranM avatar Mar 11 '15 04:03 CybranM

I've got the same problem, even tried to call the script after some time but it still seems a bit random when it shows and when it don't. The best timeout was around 300ms.

I've removed the class 'twentytwenty-container' that was there to prevent FUOC and it looks like now it is working, albeit flashing unstyled content...

setTimeout(function() { $(".compare").twentytwenty(); }, 300);

laurosollero avatar Mar 11 '15 15:03 laurosollero

Is there an update to this? I'm having the same issue, which is causing very frustrating results, as I'm trying to use multiple instances of the slider along with Owl Carousel for navigation thumbnails.

It certainly seems very random, sometimes when the page is loaded, the sliders don't load up and the style property of height is set to 0.. causing nothing to display. When resizing the window, it suddenly pops open.

Seems to be a bug?

ghost avatar May 08 '15 14:05 ghost

@laurosollero timeout solution fixes my not loading the correct size issue. Thanks!

ChristopherNeetz avatar Aug 22 '15 19:08 ChristopherNeetz

Same issue.

ghost avatar Aug 28 '15 15:08 ghost

use this instead form zurb web site : script> $(window).load(function () { $('.twentytwenty-container').eq(0).twentytwenty({ default_offset_pct: 0.33 }); $('.twentytwenty-container').eq(1).twentytwenty(); });

Winterhart avatar Sep 09 '15 17:09 Winterhart

use images loaded https://github.com/desandro/imagesloaded

        $('.before-after').imagesLoaded( function() {
            $('.before-after').twentytwenty();
        });

rubenheymans avatar Oct 30 '15 07:10 rubenheymans

Can confirm that the problem occurs when the plugin is initialized before images have fully downloaded.

A helpful patch could be to set a CSS property like this

.twentytwenty-container {
    min-height: 200px;
}

which will help the slider to at least be visible (200px tall) in case it thinks the height should be initialized to 0px.

Another patch could be to add these lines to the plugin itself:

    $(window).load(function() {
        $(window).trigger("resize.twentytwenty");
    });

So that in case the plugin is initialized before images are ready, it will trigger a resize when the document has fully loaded.

bcole808 avatar Jan 26 '17 22:01 bcole808

@Winterhart solved it for me! Thanks

blairdow avatar Sep 15 '17 18:09 blairdow

@rubenheymans This solution worked for me. Thanks

zpelgrims avatar Nov 29 '19 23:11 zpelgrims

@rubenheymans This solution using "images loaded" worked for me too. Thank you

GeorgeNicola avatar Aug 25 '20 21:08 GeorgeNicola

@rubenheymans images loaded worked perfectly for me too. Thanks a lot!

laurianne29 avatar Dec 02 '20 10:12 laurianne29

use images loaded https://github.com/desandro/imagesloaded

        $('.before-after').imagesLoaded( function() {
            $('.before-after').twentytwenty();
        });

Hey there, I am a newbie so I don't know a lot... How do I use this? I have a shopify story but I am unsure where I should put it. Do I only have to put in the

of my site and that's it? Or what else do I need to do? Thanks for any help!

bitesandtickles avatar Dec 20 '21 17:12 bitesandtickles

@bitesandtickles yes loading that script is enough. My example code is for jQuery but you can use vanilla javascript too. Read the documentation here https://github.com/desandro/imagesloaded

rubenheymans avatar Dec 20 '21 21:12 rubenheymans

@bitesandtickles yes loading that script is enough. My example code is for jQuery but you can use vanilla javascript too. Read the documentation here https://github.com/desandro/imagesloaded

Thank you! I tried using your code but it didn't work for me, do I need to change something in the code to make it fit for me? Thanks for your help, very much appreciated!

bitesandtickles avatar Dec 21 '21 17:12 bitesandtickles

@bitesandtickles we should probably discuss this somewhere else. Maybe create a stackoverflow post. Show us what you tried, where you are stuck and link it here. Add your console.log output. Make sure you are using jQuery with my code example.

rubenheymans avatar Dec 23 '21 16:12 rubenheymans