<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>_dlwldms.log</title>
        <link>https://velog.io/</link>
        <description>web publisher / frontend developer</description>
        <lastBuildDate>Sat, 27 Sep 2025 20:04:42 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>_dlwldms.log</title>
            <url>https://velog.velcdn.com/images/_dlwldms/profile/87a91ae7-7c81-41a0-8280-39e8673de3fa/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. _dlwldms.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/_dlwldms" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[JavaScript / CSS] 카드형 div 가로스크롤 / position:sticky;]]></title>
            <link>https://velog.io/@_dlwldms/CSS-JavaScript-%EC%B9%B4%EB%93%9C%ED%98%95-div-%EA%B0%80%EB%A1%9C%EC%8A%A4%ED%81%AC%EB%A1%A4-positionsticky</link>
            <guid>https://velog.io/@_dlwldms/CSS-JavaScript-%EC%B9%B4%EB%93%9C%ED%98%95-div-%EA%B0%80%EB%A1%9C%EC%8A%A4%ED%81%AC%EB%A1%A4-positionsticky</guid>
            <pubDate>Sat, 27 Sep 2025 20:04:42 GMT</pubDate>
            <description><![CDATA[<h3 id="📌-결과물">📌 결과물</h3>
<p><img src="https://velog.velcdn.com/images/_dlwldms/post/c48a7fab-7f1e-4253-b4f2-2b873120c7e4/image.gif" alt=""></p>
<h4 id="레이아웃">레이아웃</h4>
<p><img src="https://velog.velcdn.com/images/_dlwldms/post/a7a0fb6c-e94e-4c30-b60a-e25ba51984b1/image.png" alt=""></p>
<h3 id="✔️-code">✔️ CODE</h3>
<h4 id="html">HTML</h4>
<pre><code>&lt;section&gt;
  &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;horizontal_wrap&quot;&gt;
          &lt;div class=&quot;horizontal&quot;&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;첫번째 div&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;첫번째 div&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;두번째 div&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;세번째 div&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;네번째 div&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class=&quot;horizontal_div&quot;&gt;
                  &lt;h4&gt;다섯번째 div&lt;/h4&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
&lt;/section&gt;</code></pre><h4 id="css">CSS</h4>
<pre><code>section{
    width:100%;
    height:100vh;
}
.container{
    height: 3192px;
}
.horizontal_wrap{
    position: sticky;
    top: 0;
    width: 100%;
    height: 100vh;
    overflow-x:hidden;
}
.horizontal {
  position: absolute;
  width: 3192px;
  height: auto;
  top:50%;
  display: flex;
  gap: 32px;
  willchange: transform;
  transform: translate(0, -50%);
}
.horizontal_div {
  width: 500px;
  aspect-ratio: 1/1;
  background: #ddd;
  border-radius: 20px;
}
.horizontal_div:first-child{
    margin-left: 32px;
}
.horizontal_div:last-child{
    margin-right: 32px;
}</code></pre><h4 id="javascript">JavaScript</h4>
<pre><code>const container = document.querySelector(&quot;.container&quot;);
const scrollSection = document.querySelector(&quot;.horizontal&quot;);

function transform() {
    const offsetTop = container.offsetTop;
    const maxScrollX = scrollSection.scrollWidth - window.innerWidth;
    const maxScrollY = container.offsetHeight - window.innerHeight;

    const scrollY = window.scrollY - offsetTop;

    let progress = (scrollY * maxScrollX / maxScrollY);
    progress = Math.round(progress / 5) * 5;
    progress = progress &lt; 0 ? 0 : progress &gt; maxScrollX ? maxScrollX : progress;


    scrollSection.style.transform = `translate(${-(progress)}px, -50%)`
}
let ticking = false;
window.addEventListener(&quot;scroll&quot;,()=&gt;{
    if(!ticking){
        window.requestAnimationFrame(()=&gt;{
            transform();
            ticking = false;
        });
        ticking = true;
    }
})</code></pre>]]></description>
        </item>
    </channel>
</rss>