TGViewer
Html and Css & Jsآموزش Html and Css & Jsآموزش @htmlcss_channels · 22.9K subscribers
Post #301 5.3K
Html and Css & Jsآموزش Creates a horizontally scrollable image gallery | HTML & CSS با ری اکشن بهمون انرژی بدید❤️ 💎 Channel: @htmlcss_channels
<div class="gallery-container">
<div class="thumbnails"></div>
<div class="scrollbar">
<div class="thumb"></div>
</div>
<div class="slides">
<div><img src="https://picsum.photos/id/1067/540/720"></div>
<div><img src="https://picsum.photos/id/122/540/720"></div>
<div><img src="https://picsum.photos/id/188/540/720"></div>
<div><img src="https://picsum.photos/id/249/540/720"></div>
<div><img src="https://picsum.photos/id/257/540/720"></div>
<div><img src="https://picsum.photos/id/259/540/720"></div>
<div><img src="https://picsum.photos/id/283/540/720"></div>
<div><img src="https://picsum.photos/id/288/540/720"></div>
<div><img src="https://picsum.photos/id/299/540/720"></div>
</div>
</div>
.gallery-container {
display: flex;
justify-content: center;
}

.thumbnails {
display: flex;
flex-direction: column;
gap: 8px;
}

.thumbnails img {
width: 40px;
height: 40px;
cursor: pointer;
}

.scrollbar {
width: 1px;
height: 720px;
background: #ccc;
display: block;
margin: 0 0 0 8px;
}

.thumb {
width: 1px;
position: absolute;
height: 0;
background: #000;
}

.slides {
margin: 0 16px;
display: grid;
grid-auto-flow: row;
gap: 1rem;
width: calc(540px + 1rem);
padding: 0 0.25rem;
height: 720px;
overflow-y: auto;
overscroll-behavior-y: contain;
scroll-snap-type: y mandatory;
scrollbar-width: none;
}

.slides > div {
scroll-snap-align: start;
}

.slides img {
width: 540px;
object-fit: contain;
}

.slides::-webkit-scrollbar {
display: none;
}
const slideGallery = document.querySelector('.slides');
const slides = slideGallery.querySelectorAll('div');
const scrollbarThumb = document.querySelector('.thumb');
const slideCount = slides.length;
const slideHeight = 720;
const marginTop = 16;

const scrollThumb = () => {
const index = Math.floor(slideGallery.scrollTop / slideHeight);
scrollbarThumb.style.height = `${((index + 1) / slideCount) * slideHeight}px`;
};

const scrollToElement = el => {
const index = parseInt(el.dataset.id, 10);
slideGallery.scrollTo(0, index * slideHeight + marginTop);
};

document.querySelector('.thumbnails').innerHTML += [...slides]
.map(
(slide, i) => `<img src="${slide.querySelector('img').src}" data-id="${i}">`
)
.join('');

document.querySelectorAll('.thumbnails img').forEach(el => {
el.addEventListener('click', () => scrollToElement(el));
});

slideGallery.addEventListener('scroll', e => scrollThumb());

scrollThumb();


با ری اکشن بهمون انرژی بدید❤️

💎 Channel: @htmlcss_channels
  • ❤ 53
  • 👍 8
  • 🔥 2
More from @htmlcss_channels
  1. Oct 10, 2026🎰 گردونه رو بچرخون، جایزه ببر! 👀 فقط یه چرخش تا جایزه‌ت فاصله داری. 🔗https://quera.org/…
  2. Oct 10, 2026غول فناوری و هوش مصنوعی یک سرور قدرتمند برای نسل جدید پردازش‌های هوش مصنوعی و زیرساخت‌های…
  3. Oct 3, 2026HTML Shortcuts You Must Know 💎 @Htmlcss_channels | #HTML #css #JavaScript
  4. Oct 2, 2026سایت StringTune یه مجموعه از کامپوننت های آماده برای ساخت تجربه‌های تعاملی و انیمیشن‌های م…
  5. Oct 1, 2026📊 نمودارهای آماده و انیمیشن‌دار برای React با EvilCharts نمودارهایی مثل Line، Bar، Pie و…
  6. Sep 30, 2026If you have a website, incorporating an AI agent (or several) can be really helpful. And i…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →