滑块轮播

1. 实现效果

实现要点:

  1. 处理小数点后两位字体大小;
  2. 实现点击轮播效果


    image.png

    image.png

    image.png

2. 代码如下

1.html

      <!-- 可提示金额 -->
      <div slot="bill" class="top-money">
        <div class="top-money-left">
          <div class="withdrawal-top">
            <div>可提现金额 &nbsp; ¥</div>
            <div class="go-withdrawal"  @click="applyWithdrawalBill"><span>去提现</span>&nbsp;<i class="el-icon-arrow-right"></i></div>
          </div>
          <div class="withdrawal-cont" v-html="billCashList.canBillCash">{{billCashList.canBillCash}}</div>
          <div class="withdrawal-calculate">{{billCashList.totalBillCash}} - {{billCashList.refundBillCash}} - {{billCashList.breachBillCash}}</div>
          <div class="withdrawal-calculate">可提现 = 待提现 - 售后待退 - 违约抵扣</div>
        </div>
        <div class="top-money-right">
          <div class="top-money-right-all">
            <div class="top-money-right-item" v-for="(item, index) in billCashData" :key="index">
              <div class="money-title">{{item.title}} &nbsp; ¥</div>
              <div class="money-num" v-html="item.str">{{item.str}}</div>
              <div class="money-time">更新时间: {{updateTime | unixToDate}}</div>
            </div>
          </div>
          <div class="arrow-left" @click="handleArrowLeft()" v-if="isShowLeft">
            <i class="el-icon-arrow-left"></i>
          </div>
          <div class="arrow-right" @click="handleArrowRight()" v-if="isShowRight">
            <i class="el-icon-arrow-right"></i>
          </div>
        </div>
      </div>

2. js

    data() {
      return {
        rightAllWidthA: '',

        /** 显示/隐藏 右箭头 */
        isShowRight: false,

        /** 显示/隐藏 左箭头 */
        isShowLeft: false,

        /** 索引 */
        index: 0,

        /** 右边可视区域的宽 */
        boxWidth: '',

        /** 每一项的宽 */
        boxWidthItem: 271,

        /** 点击箭头-移动的距离 */
        mobileWidth: 0,

        /** 列表loading状态 */
        loading: false,

        /** 列表参数 */
        params: {
          pageNum: 1,
          pageSize: 10
          // isPrepay: 0 // 是否预付款账单 0否 1是
        },

        /** 列表数据 */
        tableData: '',

        /** 创建提现申请账单 dialog */
        dialogApplyWithdrawalBillVisible: false,

        /** 提现账单信息 已处理 */
        billCashData: [],

        /** 提现账单信息 未处理 */
        billCashList: '',
        updateTime: ''
      }
    },

    watch: {
      mobileWidth: function(newVal) {
        if (Math.abs(newVal) > 0) {
          this.isShowLeft = true
        } else if (Math.abs(newVal) === 0) {
          this.isShowLeft = false
        }
        this.isShowRight = Math.abs(newVal) <= this.rightAllWidthA - this.boxWidth
      }
    },
    methods: {
      getRedWidth() {
        this.boxWidth = document.querySelector('.top-money-right').offsetWidth
        // this.boxWidthItem = document.querySelector('.top-money-right-item').offsetWidth
      },

      /** 左箭头 */
      handleArrowLeft() {
        this.index++
        this.mobileWidth = this.boxWidthItem * this.index
        let rightAllWidth = document.querySelector('.top-money-right-all')
        this.rightAllWidthA = rightAllWidth.offsetWidth
        rightAllWidth.style.transform = 'translateX' + '(' + this.mobileWidth + 'px' + ')'
      },

      /** 右箭头 */
      handleArrowRight(index) {
        this.index--
        this.mobileWidth = this.boxWidthItem * this.index
        let rightAllWidth = document.querySelector('.top-money-right-all')
        this.rightAllWidthA = rightAllWidth.offsetWidth
        rightAllWidth.style.transform = 'translateX' + '(' + this.mobileWidth + 'px' + ')'
      },

      /** 获取账单提现信息 */
      GET_BillCashInfo() {
        this.loading = true
        API_Finance.getBillCashInfo().then(response => {
          this.loading = false
          this.billCashList = this.MixinClone(response)
          this.billCashList.totalBillCash = this.billCashList.totalBillCash.toFixed(2)
          this.billCashList.refundBillCash = this.billCashList.refundBillCash.toFixed(2)
          this.billCashList.breachBillCash = this.billCashList.breachBillCash.toFixed(2)
          this.updateTime = this.billCashList.updateTime
          for (let i in response) {
            if (i !== 'canBillCash' && i !== 'updateTime' && i !== 'isCashAmount' && i !== 'isMissContract') {
              let obj_ = {
                key: i,
                value: response[i].toFixed(2),
                title: '',
                str: ''
              }
              if (i === 'totalBillCash') {
                obj_.title = '待提现金额'
              } else if (i === 'noBillCash') {
                obj_.title = '未出账金额'
              } else if (i === 'inRefundBillCash') {
                obj_.title = '售后未完成金额'
              } else if (i === 'refundBillCash') {
                obj_.title = '售后待退金额'
              } else if (i === 'breachBillCash') {
                obj_.title = '违约代扣金额'
              }
              let splitPrice = obj_.value.split('.')
              obj_.str = `${splitPrice[0]}<span style="font-size:16px; font-weight: 400;">.${splitPrice[1]}</span>`
              this.billCashData.push(obj_)
            }
            if (i === 'canBillCash') {
              let splitPrice = response[i].toFixed(2).split('.')
              this.billCashList.canBillCash = `${splitPrice[0]}<span style="font-size:16px; font-weight: 400;">.${splitPrice[1]}</span>`
            }
          }
          // 判断初始页面是否显示右箭头
          this.isShowRight = this.billCashData.length > Math.ceil(this.boxWidth / this.boxWidthItem)
        }).catch(() => { this.loading = false })
      },
    }

3.css

<style type="text/scss" lang="scss" scoped>
.top-money {
  // overflow-x: auto;
  display: flex;
  height: 200px;
  width: 100%;
  background-color: #f5f5f5;
  border-bottom: 1px solid #e6ebf5;
  font-family: PingFangSC, PingFangSC-Regular;
  // margin-bottom: 20px;
  // background-color: #fff;
  .top-money-left {
    padding: 17px 20px 20px 20px;
    min-width: 340px;
    height: 180px;
    background: linear-gradient(165deg,#2e80ec 0%, #073be1 100%);
    border-radius: 8px;
    box-shadow: 0px 2px 4px 0px #8099dd, 0px 0px 15px 0px rgba(0,0,0,0.02);
    color: #fff;
    .withdrawal-top {
      display: flex;
      justify-content: space-between;
      font-size: 14px;
      font-weight: 400;
      text-align: left;
      line-height: 28px;
      letter-spacing: 0.26px;
      text-shadow: 0px 2px 4px 0px #8099dd; 
      .go-withdrawal {
        width: 90px;
        height: 28px;
        border: 1px solid #ffffff;
        border-radius: 4px;
        // box-shadow: 0px 2px 4px 0px #8099dd;
        border: 1px solid #e6ebf5;
        text-align: center;
        cursor: pointer;
      }
    }
    .withdrawal-cont {
      margin-top: 5px;
      margin-bottom: 10px;
      height: 56px;
      font-size: 40px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      // text-align: center;
      color: #ffffff;
      line-height: 56px;
      letter-spacing: 0.68px;
      text-shadow: 0px 2px 4px 0px #8099dd; 
    }
    .withdrawal-calculate {
      height: 24px;
      font-size: 14px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: left;
      color: #9fb7f4;
      line-height: 24px;
      letter-spacing: 0.26px;
      text-shadow: 0px 2px 4px 0px #8099dd; 
    }
  }
}
.top-money-right {
  position: relative;
  // padding: 24px 40px;
  padding: 24px 0;
  flex: 1;
  margin-left: 24px;
  // min-width: 996px;
  // width: 996px;
  width: 100%;
  height: 180px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.02);
  overflow: hidden;
  .top-money-right-all {
    // min-width: 996px;
    width: 1460px;
    height: 100%;
    display: flex;
    // justify-content: space-evenly;
    .top-money-right-item {
      height: 100%;
      // min-width: 176px;
      width: 292px;
      text-align: center;
      border-right: 1px solid #e6ebf5;
      .money-title {
        height: 20px;
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: center;
        color: #999999;
        line-height: 20px;
        letter-spacing: 0.26px;
      }
      .money-num {
        padding-top: 10px;
        height: 45px;
        font-size: 32px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        color: #333333;
        line-height: 45px;
        letter-spacing: 0.55px;
      }
      .money-time {
        height: 17px;
        font-size: 12px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: center;
        color: #999999;
        line-height: 17px;
        letter-spacing: 0.22px;
        padding-top: 39px;
      }
    }
  }
  .arrow-left {
    width: 35px;
    height: 180px;
    background: rgba(94,94,94,0.25);
    backdrop-filter: blur(3px);
    position: absolute;
    left: 0;
    top: 0px;
    line-height: 180px;
    text-align: center;
    cursor: pointer;
  }
  .arrow-right {
    width: 35px;
    height: 180px;
    background: rgba(94,94,94,0.25);
    backdrop-filter: blur(3px);
    position: absolute;
    right: 0;
    top: 0;
    line-height: 180px;
    text-align: center;
    cursor: pointer;
  }
}
</style>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容