色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

vue+rem自定義輪播圖效果

瀏覽:112日期:2022-09-28 15:00:56

使用vue+rem自定義輪播圖的實(shí)現(xiàn),供大家參考,具體內(nèi)容如下

單位使用rem進(jìn)行頁(yè)面布局,在動(dòng)態(tài)計(jì)算輪播圖整體寬度時(shí),需要把px轉(zhuǎn)換成rem,挺麻煩的。

效果如下:如果當(dāng)前圖片不是第一張和最后一張,剛好可以看到當(dāng)前圖片上一張和下一張的一部分。

vue+rem自定義輪播圖效果

具體代碼如下

<template> <div class='constructionUp'><div class='pub-hd'> <h2>施工升級(jí)包</h2> <h3>額外服務(wù)項(xiàng)目</h3></div><div id='activityDiv'> <ul num='0' id='activityUl'> <li v-for='(v,i) in listData' :key='i' @touchstart.capture='touchStart' @touchend.capture='touchEnd'> <img src='http://m.lshqa.cn/bcjs/static/imgs/package/bitmap.jpg'> <div class='liText'><p class='liTtitle'>{{v.lititle}}</p><p class='liDes'>1、開工后,客戶、設(shè)計(jì)師、項(xiàng)目管家三方進(jìn)行現(xiàn)場(chǎng)交底,若有個(gè)性化項(xiàng)目變更,執(zhí)行正常的客戶變更手續(xù)(參照:客戶變更告知書);</p><p class='liDes'>2、交底后,若客戶原因要求個(gè)性化項(xiàng)目變更,除了承擔(dān)個(gè)性化項(xiàng)目的費(fèi)用外,還要增/次的調(diào)撥費(fèi)用。</p> <p class='liPrice'> <span class='title1'>主題包價(jià)格:¥</span> <span class='title2'>4500</span> <span class='title3'>元</span></p> </div></li> </ul> <div class='pointerDiv'><span :class='[currantIndex ===0 ? ’active’ : ’’, ’pointer’]'></span><span :class='[currantIndex ===1 ? ’active’ : ’’, ’pointer’]'></span><span :class='[currantIndex ===2 ? ’active’ : ’’, ’pointer’]'></span> </div></div> </div></template> <script>export default { data () {return { listData: [{lititle: ’舊房改造’}, {lititle: ’舊房改造2’}, {lititle: ’舊房改造3’}], liWidth: 0, liNum: 0, startX: 0, endX: 0, currantIndex: 0, test: false } }, mounted () {this.initUlWidth() }, methods: {initUlWidth () { // 初始化 ul的寬度 let pit = document.documentElement.clientWidth / 750 // 當(dāng)前手機(jī)屏幕和750屏幕的比例 let oldWidth = document.getElementsByClassName(’activityLi’)[0].offsetWidth // 單個(gè)li的寬度 let marginR = getComputedStyle(document.getElementsByClassName(’activityLi’)[0], null)[’marginRight’] // 獲取單個(gè)的marginRight,帶px let marginNum = parseInt(marginR.replace(’px’, ’’)) this.liWidth = oldWidth + marginNum // 單個(gè)寬度+maringRight let liCount = parseInt(document.getElementsByClassName(’activityLi’).length)// li的個(gè)數(shù) this.liNum = liCount let ULpx = oldWidth * liCount + (liCount - 1) * marginNum // 最后一個(gè)margin不算 document.getElementById(’activityUl’).style.width = ULpx / pit + ’px’// 除以比率,讓當(dāng)前div寬度與2倍設(shè)計(jì)比例一樣,設(shè)置ul的長(zhǎng)度最后那個(gè)margin不算},touchStart (e) { // 記錄初始位置 e.preventDefault() // 阻止默認(rèn)事件,滾動(dòng)等 this.startX = e.touches[0].clientX // 記錄滑動(dòng)開始的位置},touchEnd (e) { e.preventDefault() // 阻止默認(rèn)事件 // 記錄結(jié)束位置 this.endX = e.changedTouches[0].clientX // 左滑 if (this.startX - this.endX > 30) {console.log(’左滑’)if (this.currantIndex >= this.liNum - 1) { // 不做操作} else { this.currantIndex++ document.getElementById(’activityUl’).style.left = -this.currantIndex * this.liWidth + ’px’} } // 右滑 if (this.startX - this.endX < -30) {if (this.currantIndex === 0) { // 不做操作} else { this.currantIndex-- document.getElementById(’activityUl’).style.left = -this.currantIndex * this.liWidth + ’px’} } this.startX = 0 this.endX = 0} }}</script> <style lang='less' scoped> @import '~less/base.less'; .constructionUp{width: 100%;.pub-hd{ padding: 0.8rem 0 0.6rem 0; text-align: center; background-color: #ffffff; h2{font-size: 0.32rem;color: #606771; } h3{margin-top: 0.26rem;font-size: 0.24rem;color: #b9bec4; }}#activityDiv{ padding-left: 0.4rem; background-color: #ffffff; overflow: hidden; #activityUl{position: relative;left: 0;height: 8.06rem;transition:all .35s ease-in-out;background-color: #ffffff;.activityLi{ float: left; width: 6.7rem; height: 8.06rem; &:not(:last-child){margin-right: 0.3rem; } box-shadow: 0 5px 25px 0 rgba(0,0,0,.4); img{width: 100%;height: 3.6rem; } .liText{padding: 0 0.4rem;text-align: left;.liTtitle{ padding: 0.48rem 0 0.36rem 0; font-size: 0.34rem; color: #000000;}.liDes{ font-size: 0.2rem; color:#b5b5b5;} } .liPrice{height: 0.28rem;line-height: 0.28rem;color: @c-main; //顏色換一下就好vertical-align: bottom;margin-top: 0.8rem;.title1{ display: inline-block; font-size: 0.22rem;} .title2{ display: inline-block; font-size: 0.35rem;} .title3{ display: inline-block; font-size: 0.22rem;} }} } .pointerDiv{width: 100%;height: 1.54rem;background-color: #ffffff;display: flex;align-items: center;justify-content: center;.pointer{ display: inline-block; width: 0.16rem; height: 0.16rem; background-color: #cccccc; border-radius: 100%; &:nth-child(2){margin:0 0.4rem; } &.active{background-color: @c-main; }} }} }</style>

關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

更多vue學(xué)習(xí)教程請(qǐng)閱讀專題《vue實(shí)戰(zhàn)教程》

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

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 亚洲国产老鸭窝一区二区三区 | 在线成人97观看 | 亚洲国产精品一区二区九九 | 欧美三级三级三级爽爽爽 | 精品视频一区二区三区 | 国产精品成人亚洲 | 欧美特欧美特级一片 | 99久久99久久精品免费看子伦 | 成人在免费观看视频国产 | 99久久99久久久精品久久 | 91国内精品久久久久免费影院 | 四虎免费大片aⅴ入口 | 久久免费视频99 | 男性吸女下身的视频 | 99精品在线免费观看 | 国产a级特黄的片子视频免费 | 一级做a爱久久久久久久 | 成人精品视频在线观看 | 男女视频免费网站 | 欧美人成毛片在线播放 | 国产欧美日韩在线视频 | 成人欧美视频免费看黄黄 | 女人张开腿 让男人桶视频 女人张开腿等男人桶免费视频 | 欧美在线一 | 色丁香久久 | 伊人久久青草青青综合 | 国产99视频精品草莓免视看 | 理论在线看 | 99精品久久99久久久久 | 亚洲网站在线播放 | 欧美日本一区亚洲欧美一区 | 中文字幕日韩一区二区 | 殴美一级 | 国产三级a三级三级午夜 | 最新理论三级中文在线观看 | 男女性关系视频免费观看软件 | 欧美一级久久久久久久大片 | 国产三级精品美女三级 | 欧美色成人综合 | 91成人在线免费观看 | 国产午夜精品不卡视频 |