vue3 無縫滾動 seamless-scroll

vue3中無法使用 vue-seamless-scroll,作者還沒有發(fā)布vue3版本的
github issues中有提到一個解決方法,是某個作者推薦的封裝方法,但是我更傾向于使用js版的seamless-scroll作為臨時替代方案。

npm install seamscroll --save

SeamlessScroll.vue: 可以直接拷貝

<template>
  <div class="scroll-wrap">
    <slot></slot>
  </div>
</template>
<script lang="ts">
import { defineComponent, onMounted, reactive } from 'vue';
import { init } from 'seamscroll/src';

console.log('8888', init);

export default defineComponent({
  name: 'seamlessScroll',
  components: {},
  props: {
    id: {
      type: String,
      default: '',
    },
    classOption: {
      type: Object,
      default: {
        step: 1, //速度
        hoverStop: true, //鼠標(biāo)停止
        direction: 1, //0 下 1 上 2 左 3 右
      },
    },
  },
  setup(props) {
    const data = reactive({});
    const methods = {
      checkChange(val: number) {},
    };
    onMounted(() => {
      setTimeout(() => {
        console.log(props.id);
        const config = Object.assign(
          {},
          {
            dom: document.getElementById(props.id),
          },
          props.classOption,
        );
        init(config);
      }, 100);
    });
    return {
      data,
      ...methods,
    };
  },
});
</script>

<style lang="scss" scoped>
.scroll-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}
</style>

使用:

<SeamlessScroll
      class="scroll-content"
      :class="{ scrollHeight: !needTitle }"
      :class-option="classOption"
      :id="data.id"
    >
  <ul class="dl-scroll" :id="data.id">
    <li>自己寫</li>
  </ul>
</SeamlessScroll>

注意:如果多個滾動 data.id 需要保證唯一性,可以用Math.random()等方式去生成

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容