欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實(shí)現(xiàn)簡(jiǎn)單無(wú)縫滾動(dòng)效果

 更新時(shí)間:2022年04月08日 11:04:40   作者:橡皮擦不掉的  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)簡(jiǎn)單無(wú)縫滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)簡(jiǎn)單無(wú)縫滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下

效果

實(shí)現(xiàn)思路

在vue中如何復(fù)制一份列表出來(lái)呢且不能丟失綁定的事件,很簡(jiǎn)單使用slot插槽,使用兩個(gè)插槽我們就擁有了兩個(gè)列表

<div class="listScroll" ref="box">
? ? <slot></slot>
? ? <slot></slot>
</div>

組件完整代碼

<template>
? <div class="listScroll" ref="box">
? ? <slot></slot>
? ? <slot></slot>
? </div>
</template>

<script>
export default {
? name: "listScroll",
? created() {},
? mounted() {
? ? //在盒子內(nèi)容高度小于可視高度時(shí)不滾動(dòng)
? ? if (this.boxHeight < this.ele0.clientHeight) {
? ? ? this.start(this.height);
? ? ? this.setEvet();
? ? } else {
? ? ? this.isScroll = false;
? ? }
? },
? props: {
? ? speed: {
? ? ? default: 1,
? ? ? type: Number,
? ? },
? },
? computed: {
? ? //第一個(gè)slot
? ? ele0() {
? ? ? return this.$refs.box.children[0];
? ? },
? ? //第二個(gè)slot
? ? ele1() {
? ? ? return this.$refs.box.children[1];
? ? },
? ? //盒子的可視高度
? ? boxHeight() {
? ? ? return this.$refs.box.clientHeight;
? ? },
? },
? data() {
? ? return {
? ? ? height: 0,
? ? ? isScroll: true,
? ? };
? },
? methods: {
? ? //鼠標(biāo)移入停止?jié)L動(dòng) 移出繼續(xù)滾動(dòng)
? ? setEvet() {
? ? ? this.$refs.box.onmouseenter = () => {
? ? ? ? this.isScroll = false;
? ? ? ? // this.height = 0;
? ? ? };
? ? ? this.$refs.box.onmouseleave = () => {
? ? ? ? this.isScroll = true;
? ? ? ? this.$nextTick(() => {
? ? ? ? ? this.start(this.height);
? ? ? ? });
? ? ? };
? ? },
? ? //滾動(dòng)方法
? ? start(height) {
? ? ? this.ele0.style = `transform:translateY(-${height}px);`;
? ? ? this.ele1.style = `height:${this.boxHeight}px;transform:translateY(-${height}px);overflow: hidden;`;
? ? ? if (height >= this.ele0.clientHeight) {
? ? ? ? this.height = 0;
? ? ? } else {
? ? ? ? this.height += this.speed;
? ? ? }
? ? ? if (!this.isScroll) return;
? ? ? window.requestAnimationFrame(() => {
? ? ? ? this.start(this.height);
? ? ? });
? ? },
? },
};
</script>

<style lang="less" scoped>
.listScroll {
? overflow: hidden;
}
.hover {
? overflow-y: auto;
}
.hide {
? display: none;
}
</style>

使用

<template>
? <div class="scroll">
? ? <list-scroll class="box" :speed="1">
? ? ? <div class="list">
? ? ? ? <div class="item" v-for="item in list" :key="item.xh">
? ? ? ? ? <span>{{ item.xh }}</span
? ? ? ? ? ><span>{{ item.label }}</span>
? ? ? ? </div>
? ? ? </div>
? ? </list-scroll>
? </div>
</template>

<script>
import ListScroll from "@/components/listScroll";
export default {
? name: "scroll",
? components: { ListScroll },
? data() {
? ? return {
? ? ? list: new Array(10)
? ? ? ? .fill(1)
? ? ? ? .map((s, i) => ({ xh: i + 1, label: "hello wrold" })),
? ? };
? },
};
</script>

<style lang="less" scoped>
.box {
? height: 300px;
}
.list {
? padding: 0 10px;
? width: 300px;
? .item {
? ? display: flex;
? ? justify-content: space-between;
? ? padding: 5px 0;
? ? cursor: pointer;
? ? &:hover {
? ? ? background-color: #95a5a6;
? ? }
? }
}
</style>

至此一個(gè)簡(jiǎn)單的無(wú)縫滾動(dòng)就完成了(vue2和vue3通用)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項(xiàng)目index.html中使用環(huán)境變量的代碼示例

    vue項(xiàng)目index.html中使用環(huán)境變量的代碼示例

    在Vue3中使用環(huán)境變量的方式與Vue2基本相同,下面這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目index.html中使用環(huán)境變量的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-02-02
  • vue項(xiàng)目中引入vue-datepicker插件的詳解

    vue項(xiàng)目中引入vue-datepicker插件的詳解

    這篇文章主要介紹了vue項(xiàng)目中引入vue-datepicker插件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • vuex 第三方包實(shí)現(xiàn)數(shù)據(jù)持久化的方法

    vuex 第三方包實(shí)現(xiàn)數(shù)據(jù)持久化的方法

    本文主要介紹了vuex 第三方包實(shí)現(xiàn)數(shù)據(jù)持久化的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • 如何解決element-ui動(dòng)態(tài)加載級(jí)聯(lián)選擇器默認(rèn)選中問(wèn)題

    如何解決element-ui動(dòng)態(tài)加載級(jí)聯(lián)選擇器默認(rèn)選中問(wèn)題

    這篇文章主要介紹了如何解決element-ui動(dòng)態(tài)加載級(jí)聯(lián)選擇器默認(rèn)選中問(wèn)題,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-09-09
  • vue.js做一個(gè)簡(jiǎn)單的編輯菜譜功能

    vue.js做一個(gè)簡(jiǎn)單的編輯菜譜功能

    本文通過(guò)實(shí)例代碼給大家一個(gè)簡(jiǎn)單的基于vue.js實(shí)現(xiàn)的編輯菜譜功能,代碼簡(jiǎn)答易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2018-05-05
  • Vant?Weapp組件picker選擇器初始默認(rèn)選中問(wèn)題

    Vant?Weapp組件picker選擇器初始默認(rèn)選中問(wèn)題

    這篇文章主要介紹了Vant?Weapp組件picker選擇器初始默認(rèn)選中問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • vue組件name的作用小結(jié)

    vue組件name的作用小結(jié)

    大家在寫vue項(xiàng)目的時(shí)候會(huì)遇到給組件的各種命名,接下來(lái)通過(guò)本文給大家分享vue組件name的作用小結(jié),感興趣的朋友跟隨腳本之家小編一起看看吧
    2018-05-05
  • 使用Vant完成Dialog彈框案例

    使用Vant完成Dialog彈框案例

    這篇文章主要介紹了使用Vant完成Dialog彈框案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • Vue3中使用Pinia修改State的五種方式

    Vue3中使用Pinia修改State的五種方式

    這篇文章主要介紹了Vue3中使用Pinia修改State的五種方式,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2023-11-11
  • vue可ctrl,shift多選,可添加標(biāo)記日歷組件詳細(xì)

    vue可ctrl,shift多選,可添加標(biāo)記日歷組件詳細(xì)

    這篇文章主要介紹了vue可ctrl,shift多選,可添加標(biāo)記日歷組件詳細(xì),文章通過(guò)圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09

最新評(píng)論