-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Slider / jump #413
Comments
@akiarostami daisyUI's Carousel is working with anchor links and as far as I know, this is the cleanest way to make it work with CSS (without JS). |
Thank you @saadeghi for the promp response. You are correct, I can't think of any way of doing this without javascript. Your work with CSS alone is so impressive I forget you don't have / use JS! |
Faced the same issue and was not able to find a css fix, but with js on btn click I was able to handle the behaviour like expected:
|
First thanks! DaisyUI is amazing. I'm leaving here my solution for anyone interested in solving this little limitation
ps: I'm using DaisyUI in ReactJS with typescript |
Thank you for sharing this solution! |
BBSCDigital solution worked like a charm |
Here is what worked for me in svelte: <script lang="ts">
const goTo = (event: Event) => {
event.preventDefault();
const btn = event.currentTarget as HTMLSelectElement;
const carousel = btn.parentElement!.parentElement!.parentElement!;
// EQUIVALENT: const carousel = document.querySelector('.carousel')
const href = btn.getAttribute('href')!;
const target = carousel.querySelector<HTMLDivElement>(href)!;
const left = target.offsetLeft;
carousel.scrollTo({ left: left });
};
</script>
<div class="w-full carousel">
<div id="slide1" class="relative w-full carousel-item">
<img
alt="alt"
src="https://s3.ap-south-1.amazonaws.com/litekart.in/img/untitled-design-htiheqvawifr.png"
class="w-full"
/>
<div class="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a on:click={goTo} href="#slide4" class="btn btn-circle">❮</a>
<a on:click={goTo} href="#slide2" class="btn btn-circle">❯</a>
</div>
</div>
<div id="slide2" class="relative w-full carousel-item">
<img
alt="alt"
src="https://s3.ap-south-1.amazonaws.com/litekart.in/img/untitled-360-190px-1500-380px-vzlc6ffmy4ej.png"
class="w-full"
/>
<div class="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a on:click={goTo} href="#slide1" class="btn btn-circle">❮</a>
<a on:click={goTo} href="#slide3" class="btn btn-circle">❯</a>
</div>
</div>
<div id="slide3" class="relative w-full carousel-item">
<img
alt="alt"
src="https://s3.ap-south-1.amazonaws.com/litekart.in/img/untitled-360-190px-1500-380px-vzlc6ffmy4ej.png"
class="w-full"
/>
<div class="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a on:click={goTo} href="#slide2" class="btn btn-circle">❮</a>
<a on:click={goTo} href="#slide4" class="btn btn-circle">❯</a>
</div>
</div>
<div id="slide4" class="relative w-full carousel-item">
<img
alt="alt"
src="https://s3.ap-south-1.amazonaws.com/litekart.in/img/untitled-360-190px-1500-380px-vzlc6ffmy4ej.png"
class="w-full"
/>
<div class="absolute flex justify-between transform -translate-y-1/2 left-5 right-5 top-1/2">
<a on:click={goTo} href="#slide3" class="btn btn-circle">❮</a>
<a on:click={goTo} href="#slide1" class="btn btn-circle">❯</a>
</div>
</div>
</div> |
In the Carousel component, when we change slides using prev/next or using the indicators, there is a sudden jump in the scroll location to make the Carousel the top component of the page. It would be ideal to change the page without any change in the page scroll position.
The text was updated successfully, but these errors were encountered: