【问题标题】:Is there a way to make Vuetify v-carousel move to the next item on scroll?有没有办法让 Vuetify v-carousel 移动到滚动的下一个项目?
【发布时间】:2021-12-12 02:04:48
【问题描述】:

我正在尝试使用 v-carousel 构建首页,并希望滚动到下一个项目而不是使用箭头或分隔符,我该如何实现?

这是我现在的代码

<template>
  <v-carousel vertical-delimiters 
  :vertical="true"
  :cycle="true" 
  height="100%" 
  >
    <v-carousel-item >
      <v-sheet
        color="black"
        height="100%"
        tile
      >
        <v-container
          fill-height
          fluid
        >

          <v-row
            align="center"
            justify="center"
            dense
            class ="ma-0"
          >
            <v-col
            align="center"
            justify="center"
            >

              <v-img src="imagepath"
                      max-height="350"
                      max-width="350"
                      class="ma-10"
              >
              </v-img>

              <div class="text-h4 pa-7">
                Some text
              </div>
            </v-col>
          </v-row>
        </v-container>
      </v-sheet>
    </v-carousel-item>

    <v-carousel-item>
      <v-sheet
        color="black"
        height="100%"
        tile
      >
        <v-container
          fill-height
          fluid
        >

          <v-row
            align="center"
            justify="center"
            dense
            class ="ma-0"
          >
            <v-col
            align="center"
            justify="center"
            >

              <v-img src="Image Path"
                      max-height="350"
                      max-width="350"
                      class="ma-10"
              >
              </v-img>

              <div class="text-h4 pa-7">
                Some text
              </div>
            </v-col>
          </v-row>
        </v-container>
      </v-sheet>
    </v-carousel-item>
  </v-carousel>
</template>

轮播工作得很好,但我找不到将滚动事件发送到轮播作为移动到下一个项目的事件的方法。

【问题讨论】:

    标签: javascript vue.js frontend vuetify.js carousel


    【解决方案1】:

    我认为你可以将你的 carousel 包装到 Intersection observer 中,这样你就可以观察到滚动事件,然后你就可以调用可以处理 carousel 的函数了。

    例如您必须为&lt;v-carousel&gt; 提供v-model,然后在跟踪滚动事件后,您可以增加或减少v-model 的数量。

    另一种方法是使用scroll directivev-scroll 指令允许您在窗口、指定目标或元素本身(带有 .self 修饰符)滚动时提供回调。

    【讨论】:

    • 谢谢,我会试一试,看看我能想出什么! Vue JS 的新手,所以必须玩一点,你会把“函数”放在一个方法中吗?还是直接在模板中处理?
    • 最好把你的函数放在方法中。它会比在模板中处理要清晰得多。
    猜你喜欢
    • 2021-11-07
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2011-05-15
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    相关资源
    最近更新 更多