<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Late Night Pizza]]></title><description><![CDATA[Late Night Pizza]]></description><link>https://feed.kenjones.pizza</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 00:24:54 GMT</lastBuildDate><atom:link href="https://feed.kenjones.pizza/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Svelte(Kit): Making a reusable 'Animate On Scroll (once visible)' component]]></title><description><![CDATA[Ever needed to animate in an element once it's visible on the screen?  There are multiple ways to achieve this, with even more ways to handle the animation.  I'm using 
svelte-intersection-observer to track when the element is in view, and TailwindCS...]]></description><link>https://feed.kenjones.pizza/sveltekit-reusable-animate-on-scroll-once-visible-component</link><guid isPermaLink="true">https://feed.kenjones.pizza/sveltekit-reusable-animate-on-scroll-once-visible-component</guid><category><![CDATA[Sveltekit]]></category><category><![CDATA[Tailwind CSS]]></category><category><![CDATA[Svelte]]></category><dc:creator><![CDATA[Ken Jones Pizza]]></dc:creator><pubDate>Sun, 26 Jun 2022 00:52:54 GMT</pubDate><content:encoded><![CDATA[<p>Ever needed to animate in an element once it's visible on the screen?  There are multiple ways to achieve this, with even more ways to handle the animation.  I'm using 
<a target="_blank" href="https://www.npmjs.com/package/svelte-intersection-observer"><code>svelte-intersection-observer</code></a> to track when the element is in view, and TailwindCSS classes for the animations.</p>
<h2 id="heading-check-out-the-code">Check out the code: <code>&lt;AnimatedElement&gt;</code></h2>
<pre><code class="lang-svelte">&lt;script&gt;
  import IntersectionObserver from "svelte-intersection-observer";

  let element;
  let intersecting;

  export let duration = "700ms";
  export let delay = "0";
  export let fade = false;
  export let fly = false;
  export let offset = "0";
  export let once = true;

  // Set the default to fly if 'fly' or 'fade' are not specified
  fly = !fade &amp;&amp; !fly ? true : false;
&lt;/script&gt;

&lt;IntersectionObserver
  rootMargin={`${offset}px`}
  {once}
  {element}
  bind:intersecting
&gt;
  {#if fade}
    &lt;div
      bind:this={element}
      class={`${intersecting ? "opacity-100" : "opacity-0"} transition`}
      style="transition-delay: {delay}; transition-duration: {duration}"
    &gt;
      &lt;slot {intersecting} /&gt;
    &lt;/div&gt;
  {/if}

  {#if fly}
    &lt;div
      bind:this={element}
      class={`${
        intersecting ? "opacity-100 translate-y-0" : "opacity-0 -translate-y-6"
      } transform transition`}
      style="transition-delay: {delay}; transition-duration: {duration}"
    &gt;
      &lt;slot {intersecting} /&gt;
    &lt;/div&gt;
  {/if}
&lt;/IntersectionObserver&gt;
</code></pre>
<p>I know this code could be shortened, but I'm not that concerned with that.  I'd rather have a component I can easily read.  Also note, I'm passing <code>intersecting</code> back into the slot, in case you need the trigger wherever you use the component</p>
<h2 id="heading-how-to-use">How to use:</h2>
<pre><code class="lang-svelte">&lt;AnimatedElement&gt;
   &lt;a href="/"&gt;
      &lt;img src="/img/logo.svg" class="h-16 md:h-20 lg:h-auto" alt="logo" /&gt;
    &lt;/a&gt;
&lt;/AnimatedElement&gt;
</code></pre>
<h2 id="heading-potential-improvements">Potential improvements</h2>
<p>I didn't have time to lollygag when coding this, but I would like to make this without needing the extra wrapper div inside the <code>&lt;AnimatedElement&gt;</code> component.  I don't see why this wouldn't be possible by using the <code>&lt;svelte:element this={tag}&gt;</code> tag and passing the element <code>tag</code> along with the <code>class</code> into the component.  Like this <code>&lt;AnimatedElement tag="div" class="flex"&gt;</code>.  Let me know you'd like for me to code that out.</p>
<p>Thanks for reading!  Now go grab some pizza!</p>
]]></content:encoded></item></channel></rss>