Splide Svelte不正确地基于动态选项的更新
我正在尝试使 splide 旋转木马通过更改perpage 代码>基于屏幕尺寸的Prop,但仅当
perpage
增加时,它才能起作用,减小屏幕大小最终会以非常奇怪的行为出现:
<script>
let innerWidth
$: tileNumber = innerWidth > 900 ? 2 : 1
$: carouselOptions = {
gap: '1rem',
padding: '10rem',
focus: 0,
perPage: tileNumber,
perMove: 1,
arrows: false,
pagination: false,
}
</script>
<svelte:window bind:innerWidth />
<p>{tileNumber}</p>
<Splide aria-label={title} bind:options={carouselOptions}>
{#each items as item}
<SplideSlide>
<div class="w-full h-40 {bgClass}">{item.title}</div>
</SplideSlide>
{/each}
</Splide>
因此,如果页面以小屏幕开头,将屏幕拖动到更宽的位置将将tilenumber
更改为2,然后perpage
正确更新,但是一旦为2,当tilenumber
变为1时,旋转木马仍然显示2个主要项目。当我使屏幕更小或移动尺寸屏幕时,轮播显示了3个主要项目,我不知道3个来自哪里。
I'm trying to make the Splide carousel responsive by changing the perPage
prop based on screen size, but it works only when perPage
increases, decreasing the screen size will end up in very strange behavior:
<script>
let innerWidth
$: tileNumber = innerWidth > 900 ? 2 : 1
$: carouselOptions = {
gap: '1rem',
padding: '10rem',
focus: 0,
perPage: tileNumber,
perMove: 1,
arrows: false,
pagination: false,
}
</script>
<svelte:window bind:innerWidth />
<p>{tileNumber}</p>
<Splide aria-label={title} bind:options={carouselOptions}>
{#each items as item}
<SplideSlide>
<div class="w-full h-40 {bgClass}">{item.title}</div>
</SplideSlide>
{/each}
</Splide>
So if the page starts with small screen, dragging the screen to wider position will change tileNumber
to 2, and perPage
updates properly, but once it is 2, when tileNumber
becomes 1, carousel still shows 2 main items. When I make the screen even smaller or to mobile size screen, carousel shows 3 main items, I have no idea where 3 comes from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论