<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Geoffrey</title>
    <description>The latest articles on DEV Community by Geoffrey (@geosigno).</description>
    <link>https://dev.to/geosigno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F173126%2F680d75f6-553f-434d-a570-faf92eb81fb3.jpeg</url>
      <title>DEV Community: Geoffrey</title>
      <link>https://dev.to/geosigno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/geosigno"/>
    <language>en</language>
    <item>
      <title>Seven years of performance work on simpleParallax.js, up to v8</title>
      <dc:creator>Geoffrey</dc:creator>
      <pubDate>Sat, 28 Nov 2026 15:19:27 +0000</pubDate>
      <link>https://dev.to/geosigno/seven-years-of-performance-work-on-simpleparallaxjs-up-to-v8-5459</link>
      <guid>https://dev.to/geosigno/seven-years-of-performance-work-on-simpleparallaxjs-up-to-v8-5459</guid>
      <description>&lt;p&gt;In 2019 I wrote a &lt;a href="https://dev.to/geosigno/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-cje"&gt;case study&lt;/a&gt; about simpleParallax.js, a library that adds a parallax effect directly on &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tags instead of &lt;code&gt;background-image&lt;/code&gt;. It ended with this sentence: "Performances are constant challenges against what has been done."&lt;/p&gt;

&lt;p&gt;Seven years and four major versions later, here is what that challenge looked like, and how version 8 finally fixed a bug that had been open since 2020.&lt;/p&gt;

&lt;h2&gt;
  
  
  What didn't change
&lt;/h2&gt;

&lt;p&gt;The core idea from 2019 is still there, with the same formulas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the image is wrapped in a container with &lt;code&gt;overflow: hidden&lt;/code&gt;, so it can move without breaking the layout;&lt;/li&gt;
&lt;li&gt;the image is scaled up, so it has room to move without showing blank space:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;range       = imageHeight * scale - imageHeight
progress    = (viewportBottom - imageTop) / (viewportHeight + imageHeight)
translation = progress * range - range / 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only visible change: the default &lt;code&gt;scale&lt;/code&gt; went from 1.3 to 1.5 in 7.0, when the React and vanilla versions were aligned.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;6.0 (2024): React and TypeScript.&lt;/strong&gt; The library became a React component first, with the vanilla version still available.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;6.2.1 (2025): no more useless re-renders.&lt;/strong&gt; The React version was re-rendering while the parallax was animating.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;7.0 (2026): no re-render at all while scrolling.&lt;/strong&gt; The transform is computed in the animation frame and written directly to the element's style, outside React's render cycle. The vanilla and React versions now share the same core, so they behave the same, and nothing touches the browser at import time, so it works with server-side rendering.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;8.0 (2026): a per-frame animation engine&lt;/strong&gt;, which is the rest of this post.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The bug that survived every optimization
&lt;/h2&gt;

&lt;p&gt;Since 2020 (&lt;a href="https://github.com/geosigno/simpleParallax.js/issues/47" rel="noopener noreferrer"&gt;issue #47&lt;/a&gt;), the effect stuttered on iPhone: badly in Safari, a bit less in Chrome iOS, which runs on the same WebKit engine. On a Mac it was smooth with a trackpad and jerky with a mouse wheel.&lt;/p&gt;

&lt;p&gt;None of the fixes I tried worked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;delay: 0&lt;/code&gt; (the default from 5.5.1): still jerky, sometimes worse;&lt;/li&gt;
&lt;li&gt;the vanilla version instead of React: same result;&lt;/li&gt;
&lt;li&gt;rounding the translation to a hundredth of a pixel: no change;&lt;/li&gt;
&lt;li&gt;turning off the transition on Safari (6.3): not a real fix.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I measured on an iPhone 16e. The page ran at 60 fps, and the library applied every scroll position it received. But JavaScript only received the scroll position 18 to 33 times per second, with jumps of 73 to 486 px. With a mouse wheel on a Mac, it's about 100 px per notch.&lt;/p&gt;

&lt;p&gt;That was the cause. Until 7.x, the library copied those jumps as they came, and the CSS transition used for &lt;code&gt;delay&lt;/code&gt; restarted on every new position. The problem wasn't Safari itself, it was how irregular the scroll input was. Why iOS reports the position so irregularly, maybe because scrolling is handled by the system, outside JavaScript, I couldn't verify.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: let the scroll set a target, not the position
&lt;/h2&gt;

&lt;p&gt;Version 8 removes the CSS transition entirely. The scroll only sets a target position, and on every animation frame, each image covers a fraction of the remaining distance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;dt&lt;/code&gt; is the time since the last frame, so the motion is the same at 60 Hz or 120 Hz, and the image keeps moving smoothly however irregular the scroll is. With this constant, it covers about 98% of the way after &lt;code&gt;delay&lt;/code&gt; seconds. Two other easings, &lt;code&gt;spring&lt;/code&gt; and &lt;code&gt;bounce&lt;/code&gt;, use damped springs instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Doing nothing when nothing moves
&lt;/h2&gt;

&lt;p&gt;The engine also made the idle case free:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Vanilla:&lt;/strong&gt; element positions are measured once, at init and on &lt;code&gt;refresh()&lt;/code&gt;, then cached. A frame only reads the scroll position. If it hasn't changed and every image has reached its target, the frame does nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React:&lt;/strong&gt; one shared &lt;code&gt;requestAnimationFrame&lt;/code&gt; loop for every component, in two passes: all the reads first, then all the writes, so the browser never has to recalculate styles between two images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No more IntersectionObserver.&lt;/strong&gt; In 2019 I recommended it to skip images outside the viewport. In 8.0 the vanilla version dropped it: once an idle frame costs nothing, the observer was extra work for no gain.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What about CSS scroll-driven animations?
&lt;/h2&gt;

&lt;p&gt;I tried them (&lt;code&gt;ViewTimeline&lt;/code&gt;). They were smooth on iPhone, but they ignored &lt;code&gt;delay&lt;/code&gt; and jumped when the layout changed. For a simple parallax on a stable page, they're enough, with no JavaScript at all. The library is still useful when you want the eased catch-up, the automatic scale, or older browsers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Still a constant challenge
&lt;/h2&gt;

&lt;p&gt;The 2019 sentence still holds. This time the fix didn't come from a new browser API, but from measuring what the browser actually sends instead of assuming it.&lt;/p&gt;

&lt;p&gt;simpleParallax.js is MIT-licensed, works as a React component (including &lt;code&gt;next/image&lt;/code&gt;) or in vanilla JS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Demo and docs: &lt;a href="https://simpleparallax.com" rel="noopener noreferrer"&gt;simpleparallax.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/geosigno/simpleParallax.js" rel="noopener noreferrer"&gt;github.com/geosigno/simpleParallax.js&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;8.0 release notes: &lt;a href="https://github.com/geosigno/simpleParallax.js/releases/tag/v8.0.0" rel="noopener noreferrer"&gt;v8.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>performance</category>
      <category>react</category>
    </item>
    <item>
      <title>Case study: create a parallax effect directly on &lt;img&gt; tags with JavaScript</title>
      <dc:creator>Geoffrey</dc:creator>
      <pubDate>Wed, 29 May 2019 13:26:19 +0000</pubDate>
      <link>https://dev.to/geosigno/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-cje</link>
      <guid>https://dev.to/geosigno/case-study-create-a-parallax-effect-directly-on-img-tags-with-javascript-cje</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Parallax effects in web work only with the CSS background-image property, why is&lt;br&gt;
that? &lt;strong&gt;This is not really practical.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This was a starting point for me. I wanted to have a nice parallax effect to apply directly on image tags, for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is the most natural way to use images on the web&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;background-image&lt;/em&gt; property doesn’t support the equivalent of picture tag,
&lt;em&gt;srcset&lt;/em&gt; and &lt;em&gt;sizes&lt;/em&gt; attributes easily&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;background-image&lt;/em&gt; with CMS is not optimal&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fact that I couldn’t find this kind of library/plugin anywhere was&lt;br&gt;
surprising, so** I decided to create a new one**.&lt;/p&gt;

&lt;h3&gt;
  
  
  Main objective
&lt;/h3&gt;

&lt;p&gt;I wanted to be able to add parallax effects without any change on HTML or CSS.&lt;/p&gt;

&lt;p&gt;The reason being I already had a website almost finished, and I didn’t see myself changing all my &lt;em&gt;&amp;lt; img&amp;gt;&lt;/em&gt; tags to &lt;em&gt;&amp;lt; div&amp;gt;&lt;/em&gt; with &lt;em&gt;background-image&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;This was the main thread of this library, I wanted to have a very simple way to apply parallax on any website already on production without any rework. And as a bonus, a very smooth and natural animation feeling — the effect should only give a plus and not cost anything else.&lt;/p&gt;

&lt;h3&gt;
  
  
  1st Issue: How to not break the layout?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5uiaOAwx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gpa5y29zkcto3j3naanv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5uiaOAwx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gpa5y29zkcto3j3naanv.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first concern was to manage the transition of the image without breaking the layout. Usual parallax effects are located in a very specific area created for that purpose only, the main thread of this case is the opposite.&lt;/p&gt;

&lt;p&gt;Parallax should be easily added anywhere there is an image, even if its located between two text blocs. And you don’t want the image to be transitioned anywhere on the website and potentially overlap with content.&lt;/p&gt;

&lt;h4&gt;
  
  
  Solution
&lt;/h4&gt;

&lt;p&gt;I have therefore reached the conclusion to dynamically add a container as a parent of the image. This container will have the same dimensions as the image and a hidden overflow. Now the image can translate from an infinite number of pixels without breaking the layout.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="image.jpg" alt="image" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;will become:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div style="overflow: hidden"&amp;gt;
    &amp;lt;img src="image.jpg" alt="image" /&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  2nd Issue: How to avoid blank spaces?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--74RUeA4d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/thipgev0b1h2h504eo1d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--74RUeA4d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/thipgev0b1h2h504eo1d.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So a new problem appeared, blank spaces when the image reaches its physical limit.&lt;/p&gt;

&lt;p&gt;This was very problematic, considering that the whole point was to leave the initial layout of the page unaltered. Not to mention the smooth and natural animation initially planned.&lt;/p&gt;
&lt;h4&gt;
  
  
  Solution
&lt;/h4&gt;

&lt;p&gt;I have opted for this solution: add a scaling transformation on the image.&lt;br&gt;
Meaning the image will have more matter to be transitioned with. This range can be easily calculated by:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(imageHeight * scale - imageHeight) = range
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;For example, if the image is 500px height, and we apply a 1.5 scale, that means the image will have a 250px range to translate on.&lt;/p&gt;

&lt;p&gt;Now we need to get the percentage of the image position comparing to the&lt;br&gt;
viewport, using a more laborious calculation:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;((viewportBottom - imageTop) / ((viewportHeight + imageHeight) / 100)) = percentage
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And finally transcript this percentage into the range:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;((percentage / 100) * range - range / 2) = translation
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So &lt;strong&gt;the translation can be applied gradually&lt;/strong&gt; on the image using the&lt;br&gt;
&lt;em&gt;transform: translate(translation);&lt;/em&gt; property.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons: quality of the image
&lt;/h4&gt;

&lt;p&gt;Theoretically, we can apprehend the fact that if the scale is applied to an image, we will lose quality.&lt;/p&gt;

&lt;p&gt;In practice, &lt;strong&gt;this is hardly noticeable&lt;/strong&gt; if the scale is set at 1.3 (which is the default value of the library). And even less if you cater for this by adding an image with a bigger size — meaning if your image is 500px and you want to apply a 1.5 scale, compensate by using a 750px width image.&lt;/p&gt;

&lt;h3&gt;
  
  
  Final render
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fhn3oGzh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/i1vfwvwaao4nizzwl13u.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fhn3oGzh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/i1vfwvwaao4nizzwl13u.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Performances
&lt;/h3&gt;

&lt;p&gt;With parallax animations, comes &lt;strong&gt;performance warning&lt;/strong&gt;. Thanks to &lt;a href="https://www.paulirish.com/"&gt;Paul&lt;br&gt;
Irish&lt;/a&gt; and &lt;a href="https://www.html5rocks.com/"&gt;html5rocks&lt;/a&gt;, a lot of answers were already provided and explained to an extent. Still, there is a lot to do here, some examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The scroll event is performance greedy, so the use of &lt;em&gt;Request Animation Frame&lt;/em&gt; is highly recommended. I shall not elaborate, as this subject has already been touched upon &lt;a href="https://css-tricks.com/using-requestanimationframe/"&gt;by others&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Intersection Observer API&lt;/em&gt; is really powerful and performance light to check which elements are visible in the viewport. Because there is no need to cater for images that are not in the current viewport.&lt;/li&gt;
&lt;li&gt;A key point is to reduce &lt;a href="https://gist.github.com/paulirish/5d52fb081b3570c81e3a"&gt;the
reflow&lt;/a&gt; of the browser as much as possible, one (of many) solution to this is to reduce as much as possible to fetch the viewport and element offsets.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;CSS Hardware Acceleration&lt;/em&gt; isn’t very well-know but yet powerful. Changing the &lt;em&gt;transform: translateX();&lt;/em&gt; to &lt;em&gt;transform: translate3D();&lt;/em&gt; will leverage the GPU power and offers &lt;a href="https://blog.teamtreehouse.com/increase-your-sites-performance-with-hardware-accelerated-css"&gt;better
performance&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Performances are constant challenges&lt;/strong&gt; against what has been done. And improve&lt;br&gt;
what can be improved thanks to new technologies or wrong initial implementation.&lt;/p&gt;




&lt;p&gt;This case study and this library &lt;strong&gt;only reflect my point of view&lt;/strong&gt;, which may&lt;br&gt;
not be the best. You are most welcome to challenge, debate or argue any of the&lt;br&gt;
things I said above.&lt;/p&gt;

&lt;p&gt;Last but not least, you can check the simpleParallax library on&lt;br&gt;
&lt;a href="https://simpleparallax.com/"&gt;simpleparallax.com&lt;/a&gt; and &lt;a href="https://github.com/geosigno/simpleParallax"&gt;github&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
