svelte-image-compare icon indicating copy to clipboard operation
svelte-image-compare copied to clipboard

Not working for me...

Open rchrdnsh opened this issue 5 years ago • 4 comments

using it like this:

<div class='compare'>
  <ImageCompare
    before="art-blur.jpg"
    after="art-focus.jpg"
    contain={true}
  />
</div>

...but i'm getting the same image for both sides (both are blurry, when only the before should be blurry) and the slider in the middle does not move:

Screen Shot 2020-09-27 at 11 25 56 AM

...should i be doing something differently?

It works fine with your example code with placehold.it images, but when I try to use other images it doesn't seem to work right.

rchrdnsh avatar Sep 27 '20 18:09 rchrdnsh

UPDATE:

I am using it within sapper, and when i refresh the page it does not work as described. But when I navigate away from the page it's on and come back via the sapper router, then the component works as expected...

rchrdnsh avatar Sep 27 '20 19:09 rchrdnsh

@rchrdnsh Hi, actually, I'm not really sure this component works with SSR stuff. I never used it with Sapper, so it seems we need some adaptation to the server-side. At first sight, the reason is that browser onload event is used. I'll think about what we can deal with that.

PaulMaly avatar Oct 04 '20 06:10 PaulMaly

Hi Paul,

Thank you for taking a look. Got it working really nicely except for when the page initially loads. Once I navigate to the page, or navigate away and then back again, it works great :-)

rchrdnsh avatar Oct 05 '20 07:10 rchrdnsh

I made it in sapper like this:

<script>
        import { onMount } from 'svelte';
        import ImageCompare from 'svelte-image-compare';
    
        export let data;
        $: items = [];
    
        onMount(async () => {
            items = data;
        });
</script>

{#if (items.length > 2) }
                <ImageCompare 
                    before="{items[0].url}"
                    after="{items[1].url}"
                >
                </ImageCompare>
 {/if}

I juse it as a component in that way. The onMount loads the data only on client side. The if clouse makes sure it doesnt load the ImageCompare component on SSR and also that data/items contains two images.

In theory doing this with {#if (process.browser) } might work also, but it didn't for me:

<script>
        import ImageCompare from 'svelte-image-compare';
        export let data;
</script>

{#if (process.browser) }
                <ImageCompare 
                    before="{data[0].url}"
                    after="{data[1].url}"
                >
                </ImageCompare>
{/if}

Amerlander avatar Mar 08 '21 11:03 Amerlander