vue實(shí)現(xiàn)左右點(diǎn)擊滾動(dòng)效果
本文實(shí)例為大家分享了vue實(shí)現(xiàn)左右點(diǎn)擊滾動(dòng),效果如圖

涉及功能點(diǎn)
1、在created中使用r e f s 結(jié) 合 refs結(jié)合refs結(jié)合nextTick仍然無(wú)法獲取到元素的問(wèn)題:添加定時(shí)器
2、左右按鈕是否可點(diǎn)擊根據(jù)數(shù)據(jù)以及當(dāng)前分辨率可放下的個(gè)數(shù)確認(rèn)
3、可適應(yīng)不同分辨率下的情況
代碼
<!-- ?-->
<template>
? <div>
? ? <div class="ProgressBoxTool" v-if="progressList && progressList.length">
? ? ? <div class="processBox">
? ? ? ? <div :class="currentClickNumber > 0 ? 'arrow' : 'arrow arrowOpacity'" @click="fnPrev()">
? ? ? ? ? <img :src="arrowL" alt="" />
? ? ? ? </div>
? ? ? ? <div class="fixedBox" :ref="`fixedBox`">
? ? ? ? ? <div
? ? ? ? ? ? class="centerScroll"
? ? ? ? ? ? :style="
? ? ? ? ? ? ? `width:${signleWidth *
? ? ? ? ? ? ? ? progressList.length}px;transform:translate(${scrollResultWidth}px,0);transition:1s;`
? ? ? ? ? ? "
? ? ? ? ? >
? ? ? ? ? ? <div
? ? ? ? ? ? ? class="signleTab"
? ? ? ? ? ? ? v-for="(itemP, indexP) in progressList"
? ? ? ? ? ? ? :key="indexP + 'progress'"
? ? ? ? ? ? >
? ? ? ? ? ? ? <div class="leftIcon">
? ? ? ? ? ? ? ? <img class="pregressIcon" :src="icon" alt="" />
? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? <!-- 最后一個(gè)不展示箭頭 -->
? ? ? ? ? ? ? <img
? ? ? ? ? ? ? ? v-if="progressList.length > indexP + 1"
? ? ? ? ? ? ? ? :src="iconArrow"
? ? ? ? ? ? ? ? alt=""
? ? ? ? ? ? ? ? class="arrowSquare"
? ? ? ? ? ? ? />
? ? ? ? ? ? </div>
? ? ? ? ? </div>
? ? ? ? </div>
? ? ? ? <div :class="noScrollRight ? 'arrow' : 'arrow arrowOpacity'" @click="fnNext(activeName)">
? ? ? ? ? <img :src="arrowR" alt="" />
? ? ? ? </div>
? ? ? </div>
? ? </div>
? </div>
</template>
<script>
import arrowL from '@/assets/images/emergency/arrowL.png';
import arrowR from '@/assets/images/emergency/arrowR.png';
import icon from '@/assets/images/emergency/icon.png';
import iconArrow from '@/assets/images/emergency/iconArrow.png';
export default {
? components: {},
? data() {
? ? return {
? ? ? progressList: [
? ? ? ? { type: '1' },
? ? ? ? { type: '2' },
? ? ? ? { type: '1' },
? ? ? ? { type: '2' },
? ? ? ? { type: '1' },
? ? ? ? { type: '2' },
? ? ? ? { type: '1' },
? ? ? ? { type: '2' },
? ? ? ? { type: '1' },
? ? ? ? { type: '2' }
? ? ? ],
? ? ? arrowL,
? ? ? arrowR,
? ? ? icon,
? ? ? iconArrow,
? ? ? currentProgressId: '',
? ? ? scrollResultWidth: 0, //transform滾動(dòng)的距離
? ? ? signleWidth: 215, //單個(gè)流程的寬度
? ? ? activeName: 0,
? ? ? currentClickNumber: 0,
? ? ? noScrollRight: true
? ? };
? },
? created() {
? ? this.$nextTick(() => {
? ? ? setTimeout(() => {
? ? ? ? this.initgoRightArrow();
? ? ? });
? ? });
? },
? methods: {
? ? //初始化判斷是否可以向右滾動(dòng)
? ? initgoRightArrow() {
? ? ? const currentScrollWidth = this.$refs[`fixedBox`].clientWidth;
? ? ? const canNumber = Math.floor(currentScrollWidth / this.signleWidth); //可以放下的個(gè)數(shù)
? ? ? //如果最后一個(gè)流程圖標(biāo)已經(jīng)展示出來(lái),則停止?jié)L動(dòng)
? ? ? if (this.currentClickNumber + canNumber >= this.progressList.length) {
? ? ? ? this.noScrollRight = false;
? ? ? ? return;
? ? ? }
? ? },
? ? //點(diǎn)擊上一個(gè)
? ? fnPrev() {
? ? ? //如果右點(diǎn)擊的次數(shù)大于0,才可以左滾
? ? ? if (this.currentClickNumber > 0) {
? ? ? ? this.currentClickNumber -= 1;
? ? ? ? this.noScrollRight = true;
? ? ? ? this.fnScrollWidth('reduce');
? ? ? } else {
? ? ? ? return false;
? ? ? }
? ? },
? ? //點(diǎn)擊下一個(gè)
? ? fnNext() {
? ? ? const currentScrollWidth = this.$refs[`fixedBox`].clientWidth;
? ? ? const canNumber = Math.floor(currentScrollWidth / this.signleWidth); //可以放下的個(gè)數(shù)
? ? ? //如果最后一個(gè)流程圖標(biāo)已經(jīng)展示出來(lái),則停止?jié)L動(dòng)
? ? ? if (this.currentClickNumber + canNumber >= this.progressList.length) {
? ? ? ? return;
? ? ? }
? ? ? //說(shuō)明放不下有滾動(dòng)條
? ? ? if (this.progressList.length > canNumber) {
? ? ? ? this.currentClickNumber += 1;
? ? ? ? if (this.currentClickNumber + canNumber >= this.progressList.length) {
? ? ? ? ? this.noScrollRight = false;
? ? ? ? }
? ? ? ? this.fnScrollWidth('add');
? ? ? }
? ? },
? ? //translate的寬度
? ? fnScrollWidth(type) {
? ? ? let result = 0;
? ? ? if (type === 'reduce') {
? ? ? ? result = 215;
? ? ? } else if (type === 'add') {
? ? ? ? result = -215;
? ? ? } else {
? ? ? ? result = 0;
? ? ? }
? ? ? this.scrollResultWidth += result;
? ? },
? }
};
</script>
<style lang="scss" scoped>
//中間的時(shí)間發(fā)展部分
.processBox {
? display: flex;
? align-items: center;
? justify-content: space-between;
? .arrow {
? ? width: 60px;
? ? cursor: pointer;
? }
? .arrowOpacity {
? ? cursor: default;
? ? opacity: 0.4;
? }
? .fixedBox {
? ? flex: 1;
? ? overflow: hidden;
? }
? .centerScroll {
? ? // flex: 1;
? ? box-sizing: border-box;
? ? padding: 20px 0;
? ? white-space: nowrap;
? ? // width: calc(100% - 120px);
? ? // overflow-x: auto;
? ? .signleTab {
? ? ? width: 215px;
? ? ? position: relative;
? ? ? display: inline-block;
? ? ? .leftIcon {
? ? ? ? width: 150px;
? ? ? ? text-align: center;
? ? ? ? cursor: pointer;
? ? ? ? & > .pregressIcon {
? ? ? ? ? width: 60px;
? ? ? ? ? height: 60px;
? ? ? ? }
? ? ? }
? ? ? & > .arrowSquare {
? ? ? ? position: absolute;
? ? ? ? top: 25px;
? ? ? ? right: 0;
? ? ? }
? ? }
? }
}
</style>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- VUE中鼠標(biāo)滾輪使div左右滾動(dòng)的方法詳解
- vue左右側(cè)聯(lián)動(dòng)滾動(dòng)的實(shí)現(xiàn)代碼
- vue 導(dǎo)航錨點(diǎn)_點(diǎn)擊平滑滾動(dòng),導(dǎo)航欄對(duì)應(yīng)變化詳解
- vue tab滾動(dòng)到一定高度,固定在頂部,點(diǎn)擊tab切換不同的內(nèi)容操作
- vue中實(shí)現(xiàn)點(diǎn)擊按鈕滾動(dòng)到頁(yè)面對(duì)應(yīng)位置的方法(使用c3平滑屬性實(shí)現(xiàn))
- vue+導(dǎo)航錨點(diǎn)聯(lián)動(dòng)-滾動(dòng)監(jiān)聽(tīng)和點(diǎn)擊平滑滾動(dòng)跳轉(zhuǎn)實(shí)例
- vue監(jiān)聽(tīng)滾動(dòng)事件實(shí)現(xiàn)滾動(dòng)監(jiān)聽(tīng)
- Vue.js實(shí)戰(zhàn)之通過(guò)監(jiān)聽(tīng)滾動(dòng)事件實(shí)現(xiàn)動(dòng)態(tài)錨點(diǎn)
- vue實(shí)現(xiàn)消息的無(wú)縫滾動(dòng)效果的示例代碼
- vue中使用vue-router切換頁(yè)面時(shí)滾動(dòng)條自動(dòng)滾動(dòng)到頂部的方法
相關(guān)文章
vue axios sessionID每次請(qǐng)求都不同的原因以及修改方式
這篇文章主要介紹了vue axios sessionID每次請(qǐng)求都不同的原因以及修改方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12
vue實(shí)現(xiàn)拖拽的簡(jiǎn)單案例 不超出可視區(qū)域
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)拖拽的簡(jiǎn)單案例,不超出可視區(qū)域,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Vue3監(jiān)聽(tīng)store中數(shù)據(jù)變化的三種方式
這篇文章給大家介紹了Vue3監(jiān)聽(tīng)store中數(shù)據(jù)變化的三種方法,使用watch和storeToRefs函數(shù),使用計(jì)算屬性computed和使用watchEffect函數(shù)這三種方法,文中通過(guò)代碼講解非常詳細(xì),需要的朋友可以參考下2024-01-01
vue2 d3實(shí)現(xiàn)企查查股權(quán)穿透圖股權(quán)結(jié)構(gòu)圖效果詳解
這篇文章主要為大家介紹了vue2 d3實(shí)現(xiàn)企查查股權(quán)穿透圖股權(quán)結(jié)構(gòu)圖效果詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
vue?element-ui動(dòng)態(tài)橫向統(tǒng)計(jì)表格的實(shí)現(xiàn)
這篇文章主要介紹了vue?element-ui動(dòng)態(tài)橫向統(tǒng)計(jì)表格的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue開(kāi)發(fā)調(diào)試神器vue-devtools使用詳解
這篇文章主要為大家詳細(xì)介紹了vue開(kāi)發(fā)調(diào)試神器vue-devtools的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Vue Element-ui實(shí)現(xiàn)樹形控件節(jié)點(diǎn)添加圖標(biāo)詳解
這篇文章主要為大家介紹了Element-ui實(shí)現(xiàn)樹形控件節(jié)點(diǎn)添加圖標(biāo),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2021-11-11

