欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

小程序中如何設(shè)計click-scroll組件-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)小程序中如何設(shè)計click-scroll組件的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

創(chuàng)新互聯(lián)公司專注于噶爾企業(yè)網(wǎng)站建設(shè),自適應網(wǎng)站建設(shè),商城網(wǎng)站建設(shè)。噶爾網(wǎng)站建設(shè)公司,為噶爾等地區(qū)提供建站服務。全流程按需定制網(wǎng)站,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務

一. 背景

有些業(yè)務需求,要求前端展示的內(nèi)容多時可以通過scroll的形式拖拉查看,但是太多的滾動條又造成頁面太亂,于是封裝了這個click-scroll 組件。在組件上設(shè)定好展示的位置和空間大小,在組件內(nèi)部放置實際要展示的內(nèi)容,實際展示的內(nèi)容寬度或長或短都由此組件來控制。

二. 功能

組件內(nèi)的內(nèi)容寬度超過組件寬度時,組件兩側(cè)會自動出現(xiàn)『左右移動』交互。

當內(nèi)部展示的內(nèi)容超過組件的可見區(qū)域時,可以在組件的可見區(qū)域單擊拖動查看內(nèi)容

三. 背景知識,元素大小的測量

1.偏移量(offset dimension):

元素在屏幕上占用的可見的所有空間,元素的可見大小由其高度、寬度決定,包括所有內(nèi)邊距、滾動條和邊框大小。由四個值決定:offsetHeight、offsetWidth、offsetLeft和offsetRight。

  • offsetHeight:元素在垂直方向上占用的空間大小,以像素計。包括元素的高度、(可見)水平滾動條的高度、上邊框高度和下邊框高度。

  • offsetWidth:元素在水平方向上占用的空間大小,以像素計。包括元素的寬度、(可見)垂直滾動條的寬度、左邊框?qū)挾群陀疫吙驅(qū)挾取?/p>

  • offsetLeft:元素的左外邊框至包含元素的左內(nèi)邊框之間的像素距離。 d.

  • offsetTop:元素的上外邊框至包含元素的上內(nèi)邊框之間的像素距離。

小程序中如何設(shè)計click-scroll組件

2.客戶區(qū)大小(client dimension)

元素內(nèi)容及其內(nèi)邊距所占據(jù)空間的大小,滾動條占用的空間不計算在內(nèi)。

  • clientWidth:元素內(nèi)容區(qū)寬度加上左右內(nèi)邊距的寬度

  • clientHeight: 元素內(nèi)容區(qū)高度加上上下內(nèi)邊距的高度

小程序中如何設(shè)計click-scroll組件

3.滾動大小(scroll dimension)

包含滾動內(nèi)容的元素的大小。

  • scrollHeight:在沒有滾動條的情況下,元素內(nèi)容的實際總高度。

  • scrollWidth:在沒有滾動條的情況下,元素內(nèi)容的實際總寬度。

  • scrollLeft:被隱藏在內(nèi)容區(qū)域左側(cè)的像素數(shù)。通過設(shè)置這個屬性可以改變元素的滾動位置。

  • scrollTop:被隱藏在內(nèi)容區(qū)域上方的像素數(shù)。通過設(shè)置這個屬性可以改變元素的滾動位置。

小程序中如何設(shè)計click-scroll組件

四. 組件設(shè)計思路

小程序中如何設(shè)計click-scroll組件

五. 使用文檔

slot:

參數(shù)說明類型
content組件實際要展示的內(nèi)容dom
<click-scroll>
  <template slot="content">
    <div>
      我是實際要展示的內(nèi)容啊啊啊啊啊……
    </div>
  </template>
</click-scroll>

六. 組件源碼

<template>
 <div class="hui-hui" :id="domId.compID">
  <!--向左滑動-->
  <div class="hui-drag-left"
     :class="{'hui-drag-action': drag.isLeft}"
     v-if="drag.isShow"
     @click="onClickLeft">
  </div>

  <!--展示的內(nèi)容-->
  <div :id="domId.containerID"
     class="hui-container"
     v-show="hasContent"
     ref='container'
     @mousedown="onMouseDown">
   <slot name="content"></slot>
  </div>
  <div v-show="!hasContent" class="hui-no-data">暫無數(shù)據(jù)</div>

  <!--向右滑動-->
  <div class="hui-drag-right"
     :class="{'hui-drag-action': drag.isRight}"
     v-if="drag.isShow"
     @click="onClickRight">
  </div>
 </div>
</template>

<script>
import store from '@/store'
export default {
 name: 'cards-container',
 data () {
  return {
   hasContent: false,
   domId: {
    compID: `hui-comp-${+new Date()}`,
    containerID: `hui-container-${+new Date()}`
   },
   drag: {
    isShow: false,
    isLeft: false,
    isRight: false
   }
  }
 },
 methods: {
  judgeHasContent () {
   this.hasContent = this.$slots.hasOwnProperty('content')
  },

  judgeDragIsShow () {
   const compWidth = this.getCompWidth()
   const contextMaxWidth = this.getContextMaxWidth()

   if (compWidth >= contextMaxWidth) {
    this.drag.isShow = false
   } else {
    this.drag.isShow = true
   }
   return this.drag.isShow
  },
  judgeIsLeft () {
   const containerDom = this.getContainerDom()
   const contentWidth = this.getContextMaxWidth()

   if (!containerDom && !contentWidth) this.drag.isLeft = false
   if (containerDom.offsetWidth + containerDom.scrollLeft >= contentWidth) {
    this.drag.isLeft = false
   } else {
    this.drag.isLeft = true
   }
  },
  judgeIsRight () {
   const containerDom = this.getContainerDom()

   if (!containerDom) this.drag.isRight = false
   if (containerDom.scrollLeft === 0) {
    this.drag.isRight = false
   } else {
    this.drag.isRight = true
   }
  },

  getCompDom () {
   return document.getElementById(this.domId.compID) || null
  },
  getCompWidth () {
   const compDom = this.getCompDom()
   if (!compDom) {
    return 0
   } else {
    return compDom.offsetWidth
   }
  },
  getContainerDom () {
   return document.getElementById(this.domId.containerID) || null
  },
  getContextMaxWidth () {
   if (!this.$refs.hasOwnProperty('container')) {
    return 0
   } else {
    const widthArr = []
    for(let e of this.$refs['container'].childNodes) {
     widthArr.push(e.offsetWidth)
    }
    return Math.max(...widthArr)
   }
  },

  onMouseDown (e) { // 手動滑動
   const containerDom = this.getContainerDom()
   if (!containerDom) return

   let scrollLeft = containerDom.scrollLeft
   const containerLeft = containerDom.offsetLeft
   let ev = e || window.event
   let offsetLeft = ev.clientX - containerLeft

   document.onmousemove = (e) => {
    let ev = e || window.event
    let nowOffsetLeft = ev.clientX - containerLeft
    containerDom.scrollLeft = scrollLeft + (offsetLeft - nowOffsetLeft)

    this.judgeIsLeft()
    this.judgeIsRight()
   }

   document.onmouseup = () => {
    document.onmousemove = null
    document.onmouseup = null
   }
  },

  onClickLeft () { // 向左滑動
   if (!this.hasContent && !this.drag.isLeft) return

   const containerDom = this.getContainerDom()
   if (!containerDom) return

   const scrollWidth = containerDom.offsetWidth
   containerDom.scrollLeft += scrollWidth

   this.judgeIsLeft()
   this.judgeIsRight()
  },

  onClickRight () { // 向右滑動
   if (!this.hasContent && !this.drag.isRight) return

   const containerDom = this.getContainerDom()
   if (!containerDom) return

   const scrollWidth = containerDom.offsetWidth
   containerDom.scrollLeft -= scrollWidth

   this.judgeIsLeft()
   this.judgeIsRight()
  }
 },
 updated () {
  this.$nextTick(() => {
   this.judgeHasContent()
   const isShow = this.judgeDragIsShow()
   if (isShow) {
    this.judgeIsLeft()
    this.judgeIsRight()
   }
  })
 },
 mounted () {
  this.judgeHasContent()
  const isShow = this.judgeDragIsShow()
  if (isShow) {
   this.judgeIsLeft()
   this.judgeIsRight()
  }
 }
}
</script>

感謝各位的閱讀!關(guān)于“小程序中如何設(shè)計click-scroll組件”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

文章標題:小程序中如何設(shè)計click-scroll組件-創(chuàng)新互聯(lián)
本文URL:http://www.chinadenli.net/article44/dhcphe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名品牌網(wǎng)站設(shè)計動態(tài)網(wǎng)站網(wǎng)站維護App開發(fā)自適應網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)