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

Добавляет рецепт контейнера с горизонтальным скроллом и динамическими тенями #5480

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions recipes/horizontal-scroll-with-shadow/demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<title>Горизонтальный скролл с тенями</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Slab&display=swap">

<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
font-family: "Roboto", sans-serif;
}

body {
display: flex;
justify-content: center;
align-items: center;
background-color: #18191c;
}

.component {
position: relative;
width: 600px;
height: 220px;
overflow: hidden;
}

.component__container {
display: flex;
overflow-x: scroll;
scroll-behavior: smooth;
}

.component__container::-webkit-scrollbar {
height: 8px;
}

.component__container::-webkit-scrollbar-track {
background: #1f2023;
border-radius: 4px;
}

.component__container::-webkit-scrollbar-thumb {
background: #888;
border-radius: 4px;
}

.component__container::-webkit-scrollbar-thumb:hover {
background: #555;
}

.component__container div {
min-width: 200px;
height: 200px;
margin-right: 20px;
background-color: #fff;
flex-shrink: 0;
}

.component__shadow {
position: absolute;
top: 0;
bottom: 0;
width: 50px;
pointer-events: none;
}

.scroll-shadow--left {
left: 0;
background: linear-gradient(to right, rgba(0, 0, 0, 0.5), transparent);
}

.scroll-shadow--right {
right: 0;
background: linear-gradient(to left, rgba(0, 0, 0, 0.5), transparent);
}

.scroll-shadow__shadow--hide {
display: none;
}
</style>
</head>
<body>
<div class="component">
<div class="component__container">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

<div class="component__shadow scroll-shadow scroll-shadow--left"></div>
<div class="component__shadow scroll-shadow scroll-shadow--right"></div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
const container = document.querySelector('.component__container');
const shadowLeft = document.querySelector('.scroll-shadow--left');
const shadowRight = document.querySelector('.scroll-shadow--right');

function updateShadows() {
const scrollLeft = container.scrollLeft;
const maxScrollLeft = container.scrollWidth - container.clientWidth;

if (scrollLeft > 10) {
shadowLeft.classList.remove('scroll-shadow__shadow--hide');
} else {
shadowLeft.classList.add('scroll-shadow__shadow--hide');
}

if (scrollLeft < maxScrollLeft - 10) {
shadowRight.classList.remove('scroll-shadow__shadow--hide');
} else {
shadowRight.classList.add('scroll-shadow__shadow--hide');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно упростить:

shadowLeft.classList.toggle('scroll-shadow__shadow--hide', scrollLeft <= 10);
shadowRight.classList.toggle('scroll-shadow__shadow--hide', scrollLeft >= maxScrollLeft - 10);

}

container.addEventListener('scroll', updateShadows);
window.addEventListener('resize', updateShadows);

updateShadows(); // Initial shadow update
});
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions recipes/horizontal-scroll-with-shadow/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "Реализация горизонтального скролла с тенями"
description: ""
authors:
- punkmachine
related:
tags:
---
Loading