الگو:اسلایدر: تفاوت میان نسخهها
Esfandiari (بحث | مشارکتها) صفحهای تازه حاوی «<html> <div class="fgwiki-gallery" id="fgwiki-gallery-1" dir="rtl" aria-label="گالری تصاویر" > <div class="fgwiki-gallery__viewport"> <div class="fgwiki-gallery__track"> <!-- تصویر ۱ --> <figure class="fgwiki-gallery__slide"> <img src="https://dl.faraghaib.ir/m/106/3.jpg" alt="توضیح تصویر شماره ۱" loading="eager" > <figcapt...» ایجاد کرد |
Esfandiari (بحث | مشارکتها) بدون خلاصۀ ویرایش |
||
| (۴ نسخهٔ میانیِ ایجادشده توسط همین کاربر نشان داده نشد) | |||
| خط ۴: | خط ۴: | ||
id="fgwiki-gallery-1" | id="fgwiki-gallery-1" | ||
dir="rtl" | dir="rtl" | ||
aria-label="گالری | aria-label="گالری لوازم جانبی و فروش موبایل" | ||
> | > | ||
<div class="fgwiki-gallery__viewport"> | <div class="fgwiki-gallery__viewport"> | ||
<div class="fgwiki-gallery__track"> | <div class="fgwiki-gallery__track"> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src="https://dl.faraghaib.ir/m/106/3.jpg" | src="https://dl.faraghaib.ir/m/106/3.jpg" | ||
alt=" | alt="خرید نقد و اقساط موبایل با قیمت مناسب" | ||
loading="eager" | loading="eager" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
خرید نقد و اقساط موبایل با تحویل سریع و شرایط ویژه | |||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src="https://dl.faraghaib.ir/m/106/5.jpg" | src="https://dl.faraghaib.ir/m/106/5.jpg" | ||
alt=" | alt="فروش جدیدترین گوشی های پرچمدار با گارانتی" | ||
loading="lazy" | loading="lazy" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
جدیدترین گوشی های پرچمدار با گارانتی معتبر و قیمت رقابتی | |||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src="https://dl.faraghaib.ir/m/106/7.jpg" | src="https://dl.faraghaib.ir/m/106/7.jpg" | ||
alt=" | alt="خرید انواع هندزفری سیمی و بلوتوثی با کیفیت" | ||
loading="lazy" | loading="lazy" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
انواع | خرید انواع هندزفری سیمی و بلوتوثی با صدای شفاف و کیفیت بالا | ||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src="https://dl.faraghaib.ir/m/106/8.jpg" | src="https://dl.faraghaib.ir/m/106/8.jpg" | ||
alt=" | alt="شارژر و کابل اصلی فست شارژ برای موبایل" | ||
loading="lazy" | loading="lazy" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
شارژر و کابل | شارژر و کابل اصلی فست شارژ با دوام بالا و عملکرد مطمئن | ||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src="https://dl.faraghaib.ir/m/106/9.jpg" | src="https://dl.faraghaib.ir/m/106/9.jpg" | ||
alt=" | alt="هولدر موبایل باکیفیت برای خودرو و میز کار" | ||
loading="lazy" | loading="lazy" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
هولدر موبایل باکیفیت برای خودرو و میز کار با نگهداری مطمئن | |||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
<figure class="fgwiki-gallery__slide"> | <figure class="fgwiki-gallery__slide"> | ||
<img | <img | ||
src=" | src="https://dl.faraghaib.ir/m/106/6.jpg" | ||
alt=" | alt="گلس باکیفیت و مقاوم برای محافظت از صفحه موبایل" | ||
loading="lazy" | loading="lazy" | ||
> | > | ||
<figcaption class="fgwiki-gallery__caption"> | <figcaption class="fgwiki-gallery__caption"> | ||
گلس باکیفیت و مقاوم برای محافظت بهتر از صفحه نمایش موبایل | |||
</figcaption> | </figcaption> | ||
</figure> | </figure> | ||
| خط ۸۴: | خط ۷۸: | ||
</div> | </div> | ||
<button | <button | ||
class="fgwiki-gallery__button fgwiki-gallery__button--right" | class="fgwiki-gallery__button fgwiki-gallery__button--right" | ||
type="button" | type="button" | ||
aria-label=" | aria-label="نمایش اسلاید بعدی" | ||
> | > | ||
❯ | ❯ | ||
</button> | </button> | ||
<button | <button | ||
class="fgwiki-gallery__button fgwiki-gallery__button--left" | class="fgwiki-gallery__button fgwiki-gallery__button--left" | ||
type="button" | type="button" | ||
aria-label=" | aria-label="نمایش اسلاید قبلی" | ||
> | > | ||
❮ | ❮ | ||
</button> | </button> | ||
<div class="fgwiki-gallery__dots" aria-label="ناوبری گالری"></div> | |||
<div | |||
</div> | </div> | ||
<style> | <style> | ||
.fgwiki-gallery, | .fgwiki-gallery, | ||
.fgwiki-gallery * { | .fgwiki-gallery * { | ||
| خط ۱۲۱: | خط ۱۰۵: | ||
.fgwiki-gallery { | .fgwiki-gallery { | ||
--fg-items: 3; | --fg-items: 3; | ||
--fg-gap: | --fg-gap: 18px; | ||
--fg-radius: | --fg-radius: 18px; | ||
--fg-image-height: | --fg-image-height: 300px; | ||
--fg-side-blur: 2px; | |||
--fg-side-opacity: 0.55; | |||
--fg-accent: #1473e6; | |||
--fg-card-bg: #ffffff; | |||
--fg-image-bg: #f5f7fa; | |||
--fg-caption-bg: #ffffff; | --fg-caption-bg: #ffffff; | ||
--fg-caption-color: # | --fg-caption-color: #1f2937; | ||
position: relative; | position: relative; | ||
width: min(100%, | width: min(100%, 1240px); | ||
margin: | margin: 28px auto; | ||
padding: 0 | padding: 0 56px 42px; | ||
direction: rtl; | direction: rtl; | ||
font-family: iransans, Arial, sans-serif; | font-family: iransans, Arial, sans-serif; | ||
| خط ۱۴۹: | خط ۱۳۷: | ||
width: 100%; | width: 100%; | ||
transform: translate3d(0, 0, 0); | transform: translate3d(0, 0, 0); | ||
transition: transform | transition: transform 650ms cubic-bezier(0.22, 1, 0.36, 1); | ||
will-change: transform; | will-change: transform; | ||
} | } | ||
.fgwiki-gallery__slide { | .fgwiki-gallery__slide { | ||
flex: 0 0 calc( | flex: 0 0 calc( | ||
(100% - (var(--fg-items) - 1) * var(--fg-gap)) / var(--fg-items) | (100% - (var(--fg-items) - 1) * var(--fg-gap)) / var(--fg-items) | ||
| خط ۱۶۵: | خط ۱۴۸: | ||
margin: 0; | margin: 0; | ||
overflow: hidden; | overflow: hidden; | ||
background: | background: var(--fg-card-bg); | ||
border: 1px solid rgba(0, 0, 0, 0.08); | border: 1px solid rgba(0, 0, 0, 0.08); | ||
border-radius: var(--fg-radius); | border-radius: var(--fg-radius); | ||
box-shadow: 0 | box-shadow: 0 10px 28px rgba(0, 0, 0, 0.10); | ||
transition: | |||
transform 450ms ease, | |||
filter 450ms ease, | |||
opacity 450ms ease, | |||
box-shadow 450ms ease; | |||
} | } | ||
| خط ۱۷۵: | خط ۱۶۳: | ||
width: 100%; | width: 100%; | ||
height: var(--fg-image-height); | height: var(--fg-image-height); | ||
padding: 10px; | |||
object-fit: | background: var(--fg-image-bg); | ||
object-fit: contain; | |||
object-position: center; | object-position: center; | ||
border: 0; | border: 0; | ||
} | } | ||
.fgwiki-gallery__caption { | .fgwiki-gallery__caption { | ||
min-height: 72px; | |||
padding: 14px 16px 16px; | |||
min-height: | |||
padding: 14px 16px | |||
color: var(--fg-caption-color); | color: var(--fg-caption-color); | ||
background: var(--fg-caption-bg); | background: var(--fg-caption-bg); | ||
font-size: 14px; | font-size: 14px; | ||
font-weight: | font-weight: 700; | ||
line-height: 1. | line-height: 1.9; | ||
text-align: right; | text-align: right; | ||
} | } | ||
.fgwiki-gallery__slide:not(.is-center) { | |||
filter: blur(var(--fg-side-blur)); | |||
opacity: var(--fg-side-opacity); | |||
transform: scale(0.94); | |||
} | |||
.fgwiki-gallery__slide.is-center { | |||
filter: none; | |||
opacity: 1; | |||
transform: scale(1.03); | |||
box-shadow: 0 16px 36px rgba(20, 115, 230, 0.18); | |||
border-color: rgba(20, 115, 230, 0.18); | |||
} | |||
.fgwiki-gallery__button { | .fgwiki-gallery__button { | ||
position: absolute; | position: absolute; | ||
top: calc(50% - | top: calc(50% - 24px); | ||
z-index: | z-index: 15; | ||
display: flex; | display: flex; | ||
align-items: center; | align-items: center; | ||
justify-content: center; | justify-content: center; | ||
width: | width: 44px; | ||
height: | height: 44px; | ||
padding: 0; | padding: 0; | ||
color: #ffffff; | color: #ffffff; | ||
background: rgba( | background: rgba(17, 24, 39, 0.78); | ||
border: 0; | border: 0; | ||
border-radius: 50%; | border-radius: 50%; | ||
box-shadow: 0 | box-shadow: 0 6px 18px rgba(0, 0, 0, 0.24); | ||
font-family: Arial, sans-serif; | font-family: Arial, sans-serif; | ||
font-size: 24px; | font-size: 24px; | ||
| خط ۲۳۹: | خط ۲۲۶: | ||
.fgwiki-gallery__button:focus-visible { | .fgwiki-gallery__button:focus-visible { | ||
outline: 3px solid rgba(20, 115, 230, 0. | outline: 3px solid rgba(20, 115, 230, 0.30); | ||
outline-offset: 3px; | outline-offset: 3px; | ||
} | } | ||
| خط ۲۵۰: | خط ۲۳۷: | ||
left: 0; | left: 0; | ||
} | } | ||
.fgwiki-gallery__dots { | .fgwiki-gallery__dots { | ||
| خط ۲۶۷: | خط ۲۵۰: | ||
.fgwiki-gallery__dot { | .fgwiki-gallery__dot { | ||
width: | width: 9px; | ||
height: | height: 9px; | ||
padding: 0; | padding: 0; | ||
background: # | background: #c7ced8; | ||
border: 0; | border: 0; | ||
border-radius: 50%; | border-radius: 50%; | ||
| خط ۲۷۶: | خط ۲۵۹: | ||
transition: | transition: | ||
width 250ms ease, | width 250ms ease, | ||
background-color 250ms ease; | background-color 250ms ease, | ||
opacity 250ms ease; | |||
} | } | ||
| خط ۲۸۲: | خط ۲۶۶: | ||
width: 24px; | width: 24px; | ||
background: var(--fg-accent); | background: var(--fg-accent); | ||
border-radius: | border-radius: 999px; | ||
} | } | ||
| خط ۲۸۹: | خط ۲۷۳: | ||
outline-offset: 2px; | outline-offset: 2px; | ||
} | } | ||
@media (max-width: 900px) { | @media (max-width: 900px) { | ||
.fgwiki-gallery { | .fgwiki-gallery { | ||
--fg-items: 2; | --fg-items: 2; | ||
--fg-image-height: | --fg-image-height: 280px; | ||
--fg-side-blur: 1.5px; | |||
padding-right: 46px; | |||
padding-left: 46px; | |||
} | |||
.fgwiki-gallery__caption { | |||
min-height: 68px; | |||
font-size: 13px; | |||
} | } | ||
.fgwiki-gallery__button { | .fgwiki-gallery__button { | ||
width: | width: 40px; | ||
height: | height: 40px; | ||
font-size: 21px; | font-size: 21px; | ||
} | } | ||
} | } | ||
@media (max-width: 600px) { | @media (max-width: 600px) { | ||
| خط ۳۱۸: | خط ۲۹۹: | ||
--fg-items: 1; | --fg-items: 1; | ||
--fg-gap: 12px; | --fg-gap: 12px; | ||
--fg-image-height: | --fg-image-height: 260px; | ||
--fg-side-blur: 0; | |||
--fg-side-opacity: 1; | |||
width: 100%; | width: 100%; | ||
padding-right: 36px; | padding-right: 36px; | ||
padding-left: 36px; | padding-left: 36px; | ||
} | |||
.fgwiki-gallery__slide, | |||
.fgwiki-gallery__slide.is-center, | |||
.fgwiki-gallery__slide:not(.is-center) { | |||
filter: none; | |||
opacity: 1; | |||
transform: none; | |||
} | } | ||
.fgwiki-gallery__caption { | .fgwiki-gallery__caption { | ||
min-height: | min-height: 62px; | ||
padding: 12px 14px; | padding: 12px 14px; | ||
font-size: 13px; | font-size: 13px; | ||
line-height: 1.8; | |||
} | } | ||
| خط ۳۳۴: | خط ۳۲۵: | ||
width: 34px; | width: 34px; | ||
height: 34px; | height: 34px; | ||
font-size: | font-size: 18px; | ||
} | } | ||
} | } | ||
@media (prefers-reduced-motion: reduce) { | @media (prefers-reduced-motion: reduce) { | ||
.fgwiki-gallery__track, | .fgwiki-gallery__track, | ||
.fgwiki-gallery__slide | .fgwiki-gallery__slide, | ||
.fgwiki-gallery__button, | .fgwiki-gallery__button, | ||
.fgwiki-gallery__dot { | .fgwiki-gallery__dot { | ||
| خط ۳۵۵: | خط ۳۴۵: | ||
document.querySelectorAll(".fgwiki-gallery").forEach(function (slider) { | document.querySelectorAll(".fgwiki-gallery").forEach(function (slider) { | ||
const track = slider.querySelector(".fgwiki-gallery__track"); | const track = slider.querySelector(".fgwiki-gallery__track"); | ||
const | const originalSlides = Array.from( | ||
slider.querySelectorAll(".fgwiki-gallery__slide") | slider.querySelectorAll(".fgwiki-gallery__slide") | ||
); | ); | ||
const rightButton = slider.querySelector( | const rightButton = slider.querySelector(".fgwiki-gallery__button--right"); | ||
const leftButton = slider.querySelector(".fgwiki-gallery__button--left"); | |||
const dotsContainer = slider.querySelector(".fgwiki-gallery__dots"); | |||
const leftButton = slider.querySelector( | |||
const dotsContainer = slider.querySelector( | |||
if (!track || | if (!track || originalSlides.length === 0) { | ||
return; | return; | ||
} | } | ||
| خط ۳۷۶: | خط ۳۶۰: | ||
let touchStartX = 0; | let touchStartX = 0; | ||
let touchEndX = 0; | let touchEndX = 0; | ||
let isAnimating = false; | |||
const autoPlayDelay = 3500; | const autoPlayDelay = 3500; | ||
| خط ۳۸۸: | خط ۳۷۱: | ||
} | } | ||
function | function cleanupClones() { | ||
Array.from(track.querySelectorAll(".is-clone")).forEach(function (node) { | |||
node.remove(); | |||
}); | |||
} | } | ||
function | function buildInfiniteTrack() { | ||
cleanupClones(); | |||
const | const visibleItems = getVisibleItems(); | ||
const | const slides = Array.from(track.children).filter(function (slide) { | ||
return !slide.classList.contains("is-clone"); | |||
}); | |||
const prependClones = slides.slice(-visibleItems).map(function (slide) { | |||
const clone = slide.cloneNode(true); | |||
clone.classList.add("is-clone"); | |||
clone.setAttribute("aria-hidden", "true"); | |||
return clone; | |||
}); | |||
const appendClones = slides.slice(0, visibleItems).map(function (slide) { | |||
const clone = slide.cloneNode(true); | |||
clone.classList.add("is-clone"); | |||
clone.setAttribute("aria-hidden", "true"); | |||
return clone; | |||
}); | |||
prependClones.forEach(function (clone) { | |||
track.insertBefore(clone, track.firstChild); | |||
} | }); | ||
appendClones.forEach(function (clone) { | |||
track.appendChild(clone); | |||
} | }); | ||
currentIndex = visibleItems; | |||
updateSlider(false); | |||
} | } | ||
function | function getAllSlides() { | ||
return Array.from(track.querySelectorAll(".fgwiki-gallery__slide")); | |||
} | |||
function getRealSlidesCount() { | |||
return originalSlides.length; | |||
} | |||
function getSlideStep() { | |||
const slides = getAllSlides(); | |||
if (slides.length < 2) { | |||
return slides[0] ? slides[0].getBoundingClientRect().width : 0; | |||
} | |||
const firstSlide = slides[0].getBoundingClientRect(); | |||
const secondSlide = slides[1].getBoundingClientRect(); | |||
return Math.abs(secondSlide.left - firstSlide.left); | |||
} | } | ||
function updateDots() { | function updateDots() { | ||
const dots = dotsContainer.querySelectorAll( | const visibleItems = getVisibleItems(); | ||
const realSlidesCount = getRealSlidesCount(); | |||
const maxDotIndex = Math.max(0, realSlidesCount - visibleItems); | |||
const realIndex = ((currentIndex - visibleItems) % realSlidesCount + realSlidesCount) % realSlidesCount; | |||
const activeDotIndex = Math.min(realIndex, maxDotIndex); | |||
const dots = dotsContainer.querySelectorAll(".fgwiki-gallery__dot"); | |||
dots.forEach(function (dot, index) { | dots.forEach(function (dot, index) { | ||
const isActive = index === currentIndex; | const isActive = index === activeDotIndex; | ||
dot.classList.toggle("is-active", isActive); | |||
dot.setAttribute("aria-current", isActive ? "true" : "false"); | |||
}); | |||
} | |||
function updateCenterState() { | |||
const visibleItems = getVisibleItems(); | |||
const centerOffset = Math.floor(visibleItems / 2); | |||
const centerIndex = currentIndex + centerOffset; | |||
const slides = getAllSlides(); | |||
slides.forEach(function (slide, index) { | |||
slide.classList.toggle("is-center", index === centerIndex); | |||
}); | }); | ||
} | } | ||
function updateSlider(animate) { | function updateSlider(animate) { | ||
const | const step = getSlideStep(); | ||
const offset = currentIndex * step; | |||
if (!animate) { | if (!animate) { | ||
| خط ۴۷۰: | خط ۴۶۹: | ||
} | } | ||
track.style.transform = "translate3d(" + offset + "px, 0, 0)"; | |||
track.style.transform = | |||
updateDots(); | updateDots(); | ||
updateCenterState(); | |||
if (!animate) { | if (!animate) { | ||
| خط ۴۸۸: | خط ۴۸۱: | ||
}); | }); | ||
} | } | ||
} | |||
function jumpIfNeeded() { | |||
const visibleItems = getVisibleItems(); | |||
const realSlidesCount = getRealSlidesCount(); | |||
if (currentIndex >= realSlidesCount + visibleItems) { | |||
currentIndex = visibleItems; | |||
updateSlider(false); | |||
} else if (currentIndex < visibleItems) { | |||
currentIndex = realSlidesCount + visibleItems - 1; | |||
updateSlider(false); | |||
} | |||
updateCenterState(); | |||
updateDots(); | |||
} | } | ||
function goToSlide(index) { | function goToSlide(index) { | ||
currentIndex = | if (isAnimating) { | ||
return; | |||
} | |||
isAnimating = true; | |||
currentIndex = index; | |||
updateSlider(true); | updateSlider(true); | ||
window.setTimeout(function () { | |||
jumpIfNeeded(); | |||
isAnimating = false; | |||
}, 680); | |||
} | } | ||
function moveRight() { | function moveRight() { | ||
goToSlide(currentIndex + 1); | goToSlide(currentIndex + 1); | ||
} | } | ||
function moveLeft() { | function moveLeft() { | ||
goToSlide(currentIndex - 1); | goToSlide(currentIndex - 1); | ||
} | |||
function createDots() { | |||
const visibleItems = getVisibleItems(); | |||
const dotsCount = Math.max(1, getRealSlidesCount() - visibleItems + 1); | |||
dotsContainer.innerHTML = ""; | |||
for (let index = 0; index < dotsCount; index += 1) { | |||
const dot = document.createElement("button"); | |||
dot.type = "button"; | |||
dot.className = "fgwiki-gallery__dot"; | |||
dot.setAttribute("aria-label", "نمایش اسلاید شماره " + (index + 1)); | |||
dot.addEventListener("click", function () { | |||
currentIndex = getVisibleItems() + index; | |||
updateSlider(true); | |||
restartAutoPlay(); | |||
}); | |||
dotsContainer.appendChild(dot); | |||
} | |||
updateDots(); | |||
} | } | ||
| خط ۵۰۸: | خط ۵۵۰: | ||
stopAutoPlay(); | stopAutoPlay(); | ||
if ( | if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) { | ||
return; | return; | ||
} | } | ||
| خط ۵۸۸: | خط ۶۲۸: | ||
window.addEventListener("resize", function () { | window.addEventListener("resize", function () { | ||
buildInfiniteTrack(); | |||
createDots(); | createDots(); | ||
}); | }); | ||
| خط ۶۰۴: | خط ۶۴۴: | ||
}, | }, | ||
{ | { | ||
threshold: 0. | threshold: 0.2 | ||
} | } | ||
); | ); | ||
| خط ۶۱۳: | خط ۶۵۳: | ||
} | } | ||
buildInfiniteTrack(); | |||
createDots(); | createDots(); | ||
}); | }); | ||
})(); | })(); | ||
</script> | </script> | ||
</html> | </html> | ||