From db7e72f8f3b67049395302d25f2548062f094d54 Mon Sep 17 00:00:00 2001 From: jur-ng <111122756+jur-ng@users.noreply.github.com> Date: Thu, 25 May 2023 15:14:03 +0200 Subject: [PATCH] =?UTF-8?q?fix(hash-navigation):=20get=20active=20slide=20?= =?UTF-8?q?element=20using=20the=20old=20method=20if=20Virtual=20is=20not?= =?UTF-8?q?=20being=E2=80=A6=20(#6704)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * get active slide element using the old method if Virtual is not being used * Fix linting issues * Improve solution --- src/modules/hash-navigation/hash-navigation.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modules/hash-navigation/hash-navigation.js b/src/modules/hash-navigation/hash-navigation.js index 8791daa98..e259f6f46 100644 --- a/src/modules/hash-navigation/hash-navigation.js +++ b/src/modules/hash-navigation/hash-navigation.js @@ -31,9 +31,10 @@ export default function HashNavigation({ swiper, extendParams, emit, on }) { const onHashChange = () => { emit('hashChange'); const newHash = document.location.hash.replace('#', ''); - const activeSlideEl = swiper.slidesEl.querySelector( - `[data-swiper-slide-index="${swiper.activeIndex}"]`, - ); + const activeSlideEl = + swiper.virtual && swiper.params.virtual.enabled + ? swiper.slidesEl.querySelector(`[data-swiper-slide-index="${swiper.activeIndex}"]`) + : swiper.slides[swiper.activeIndex]; const activeSlideHash = activeSlideEl ? activeSlideEl.getAttribute('data-hash') : ''; if (newHash !== activeSlideHash) { const newIndex = swiper.params.hashNavigation.getSlideIndex(swiper, newHash); @@ -43,9 +44,10 @@ export default function HashNavigation({ swiper, extendParams, emit, on }) { }; const setHash = () => { if (!initialized || !swiper.params.hashNavigation.enabled) return; - const activeSlideEl = swiper.slidesEl.querySelector( - `[data-swiper-slide-index="${swiper.activeIndex}"]`, - ); + const activeSlideEl = + swiper.virtual && swiper.params.virtual.enabled + ? swiper.slidesEl.querySelector(`[data-swiper-slide-index="${swiper.activeIndex}"]`) + : swiper.slides[swiper.activeIndex]; const activeSlideHash = activeSlideEl ? activeSlideEl.getAttribute('data-hash') || activeSlideEl.getAttribute('data-history') : '';