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

Threshold value having no effect (SvelteKit) #37

Open
hardingjam opened this issue Jan 18, 2022 · 2 comments
Open

Threshold value having no effect (SvelteKit) #37

hardingjam opened this issue Jan 18, 2022 · 2 comments

Comments

@hardingjam
Copy link

<IntersectionObserver once element={node} let:intersecting threshold={0.1}>
		<div bind:this={node}>
			{#if intersecting}
				<img
					on:load={imageIsLoaded}
					src={image}
					alt={name}
				/>
			{/if}
		</div>
	</IntersectionObserver>

Regardless of the low threshold, the images only load when 100% intersected with the viewport. Is this a known issue, or am I doing something wrong?

@metonym
Copy link
Owner

metonym commented Jan 22, 2022

Here's an adapted Svelte REPL that demos a custom threshold (0.5); even changing it to 0.1 should have an effect.

I wonder if it could be a styling issue? Is this div actually below the viewport?

In your example, the image isn't rendered at all initially. Perhaps the div needs a minimum height for the threshold to apply?

@lvnam96
Copy link

lvnam96 commented Apr 21, 2023

as @metonym said, in order to let IntersectionObserver works, the bind:this element (div in your example) must have "visible" pixels initially (height & width must be at least 1px).

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