国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

el-table溢出隱藏 鼠標(biāo)移入顯示tooltip邏輯

這篇具有很好參考價(jià)值的文章主要介紹了el-table溢出隱藏 鼠標(biāo)移入顯示tooltip邏輯。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

el-table

文件 element-ui/packages/table/src/table-body.js 截取部分代碼

export default {
  render(h) {
    return (
      <table>
        <tbody>
          {/* 表格內(nèi)容 ... */}
          {/* 一個(gè)表格 只渲染一個(gè) tooltip */}
          <el-tooltip effect={this.table.tooltipEffect} placement="top" ref="tooltip" content={this.tooltipContent}></el-tooltip>
        </tbody>
      </table>
    );
  },
  created() {
    this.activateTooltip = debounce(50, tooltip => tooltip.handleShowPopper());
  },
  methods: {
    handleCellMouseEnter(event, row) {  // 鼠標(biāo)移入表格項(xiàng) 觸發(fā)事件
      const table = this.table;
      const cell = getCell(event);

      if (cell) {
        const column = getColumnByCell(table, cell);
        const hoverState = table.hoverState = { cell, column, row };
        table.$emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, event);
      }
      // 判斷是否text-overflow, 如果是就顯示tooltip
      const cellChild = event.target.querySelector('.cell');
      if (!(hasClass(cellChild, 'el-tooltip') && cellChild.childNodes.length)) {
        return;
      }
      // use range width instead of scrollWidth to determine whether the text is overflowing
      // to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3
      const range = document.createRange();
      range.setStart(cellChild, 0);
      range.setEnd(cellChild, cellChild.childNodes.length);
      const rangeWidth = range.getBoundingClientRect().width;
      const padding = (parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) +
        (parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0);
      if ((rangeWidth + padding > cellChild.offsetWidth || cellChild.scrollWidth > cellChild.offsetWidth) && this.$refs.tooltip) {
        // 1. 判斷: 如果寬度溢出
        const tooltip = this.$refs.tooltip;
        // TODO 會(huì)引起整個(gè) Table 的重新渲染,需要優(yōu)化
        this.tooltipContent = cell.innerText || cell.textContent; // 2. 表格項(xiàng)內(nèi)容 賦值給 tooltip顯示
        tooltip.referenceElm = cell;  // 3. 替換referenceElm, tooltip通過Popper.js 計(jì)算顯示的tooltip和referenceElm的相對(duì)位置
        tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none');
        tooltip.doDestroy();	// 取消tooltip上一系列綁定事件
        tooltip.setExpectedState(true);
        this.activateTooltip(tooltip);  // 4. 顯示tooltip
      }
    },
    handleCellMouseLeave(event) { // 鼠標(biāo)溢出表格項(xiàng) 觸發(fā)事件
      const tooltip = this.$refs.tooltip;
      if (tooltip) {
        tooltip.setExpectedState(false);
        tooltip.handleClosePopper();  // 隱藏tooltip
      }
      const cell = getCell(event);
      if (!cell) return;

      const oldHoverState = this.table.hoverState || {};
      this.table.$emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
    },
  }
}

記錄點(diǎn)

  1. 鼠標(biāo)事件
    mouseenter/mouseleave(新),mouseover/mouseout(舊)
    新的鼠標(biāo)移入移出事件,去掉了冒泡和捕獲的特性
    • mouseenter:鼠標(biāo)第一次移動(dòng)到元素區(qū)域時(shí)觸發(fā) (新)
    • mouseleave:移出時(shí)觸發(fā)(新)
    • mousemove:在元素上移動(dòng)時(shí)觸發(fā)(一直觸發(fā))
    • mouseover:鼠標(biāo)移動(dòng)到元素上時(shí)觸發(fā)(舊)
    • mouseout:從元素上移開時(shí)觸發(fā)(舊)
  2. 步驟
    • el-tooltiptbody的子節(jié)點(diǎn),一個(gè)表格,只渲染一個(gè) el-tooltip
    • 監(jiān)聽鼠標(biāo)移入事件 mouseenter,判斷表格項(xiàng)內(nèi)容是否溢出
    • 如果溢出
      • 表格項(xiàng)內(nèi)容賦值給 tooltipContent 顯示隱藏內(nèi)容
      • 替換referenceElm, tooltip通過 Popper.js 計(jì)算顯示的 tooltipreferenceElm 的相對(duì)位置
      • 顯示 tooltip
    • 監(jiān)聽鼠標(biāo)移開事件 mouseleave,隱藏 tooltip

el-tooltip

文件 element-ui/packages/tooltip/src/main.js 截取部分代碼

const PopperJS = require('element-ui/src/utils/popper.js');
export default {
  beforeCreate() {
    this.popperVM = new Vue({
      data: { node: '' },
      render(h) {
        return this.node;
      }
    }).$mount();
    this.debounceClose = debounce(200, () => this.handleClosePopper());
  },
  render(h) {
    if (this.popperVM) {
      this.popperVM.node = (
        <transition
          name={ this.transition }
          onAfterLeave={ this.doDestroy }>
          <div
            onMouseleave={ () => { this.setExpectedState(false); this.debounceClose(); } }
            onMouseenter= { () => { this.setExpectedState(true); } }
            ref="popper"
            role="tooltip"
            id={this.tooltipId}
            aria-hidden={ (this.disabled || !this.showPopper) ? 'true' : 'false' }
            v-show={!this.disabled && this.showPopper}
            class={
              ['el-tooltip__popper', 'is-' + this.effect, this.popperClass]
            }>
            {/* 具名插槽 content 渲染在tooltip */}
            { this.$slots.content || this.content }
          </div>
        </transition>);
    }

    const firstElement = this.getFirstElement();  
    if (!firstElement) return null;

    const data = firstElement.data = firstElement.data || {};
    data.staticClass = this.addTooltipClass(data.staticClass);

    return firstElement;  // 找到默認(rèn)插槽 default 顯示在組件位置
  },
  mounted() {
    this.referenceElm = this.$el;
    // 給 referenceElm 綁定一系列事件, 包括: mouseenter mouseleave
    // ...
    
    if (this.value && this.popperVM) {
      this.popperVM.$nextTick(() => {
        if (this.value) {
          this.updatePopper();
        }
      });
    }
  },
  methods: {
    updatePopper() {
      const popperJS = this.popperJS;
      if (popperJS) {
        popperJS.update();
        if (popperJS._popper) {
          popperJS._popper.style.zIndex = PopupManager.nextZIndex();
        }
      } else {
        this.createPopper();
      }
    },
    createPopper() { // 省略...只剩下需要的邏輯
      let reference = this.referenceElm = this.referenceElm || this.reference || this.$refs.reference;
      const popper = this.popperElm = this.popperElm || this.popper || this.$refs.popper; // 提示信息ref 對(duì)應(yīng)的DOM
      const options = this.popperOptions;

      if (!popper || !reference) return;
      if (this.appendToBody) document.body.appendChild(this.popperElm); // 渲染在body節(jié)點(diǎn)下
      /**
       * reference: 默認(rèn)插槽/鼠標(biāo)移入移出顯示tooltip相對(duì)的元素
       * popper: 提示信息ref 對(duì)應(yīng)的DOM (tooltip)
       * option: 一些配置
       */
      this.popperJS = new PopperJS(reference, popper, options);
      // ...
    }
  }
}

記錄點(diǎn):文章來源地址http://www.zghlxwxcb.cn/news/detail-495133.html

  1. render
    1. 找到默認(rèn)插槽 default 顯示在組件位置
    2. 提示信息:transition + 具名插槽 content,鼠標(biāo)移入referenceElm,顯示提示信息
  2. mounted:給 referenceElm 綁定一系列事件, 包括: mouseentermouseleave,調(diào)用 updatePopper
  3. 調(diào)用 createPopper
    1. 通過 Popper.js 計(jì)算顯示的 提示信息 和 referenceElm 的相對(duì)位置
    2. 關(guān)鍵代碼:this.popperJS = new PopperJS(reference, popper, options);
      • reference: 默認(rèn)插槽/referenceElm,鼠標(biāo)移入移出顯示 提示信息 相對(duì)的元素
      • popper: 提示信息ref 對(duì)應(yīng)的DOM (tooltip)
      • option: 一些配置

到了這里,關(guān)于el-table溢出隱藏 鼠標(biāo)移入顯示tooltip邏輯的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • el-table 設(shè)置行背景顏色 鼠標(biāo)移入高亮問題處理

    el-table 設(shè)置行背景顏色 鼠標(biāo)移入高亮問題處理

    后端返回表格數(shù)據(jù),有特定行數(shù)需要用顏色標(biāo)識(shí)。類似于以下需求: 方式 區(qū)別 :row-class-name=“tableRowClassName” 已返回類名的形式設(shè)置樣式,代碼整潔,但是會(huì)鼠標(biāo)高亮,導(dǎo)致背景顏色失效 :cell-style=“cellStyle” 以返回樣式的形式設(shè)置,無鼠標(biāo)高亮問題 2.1 表格代碼 2.2 :row-cla

    2024年02月15日
    瀏覽(21)
  • el-button實(shí)現(xiàn)按鈕,鼠標(biāo)移入顯示,移出隱藏

    el-button實(shí)現(xiàn)按鈕,鼠標(biāo)移入顯示,移出隱藏

    2023.8.18今天我學(xué)習(xí)了 如何實(shí)現(xiàn)鼠標(biāo)移入顯示按鈕,鼠標(biāo)移出隱藏按鈕。 效果如圖: 鼠標(biāo)移入時(shí): 鼠標(biāo)移出時(shí): ? ?原本我是想直接在el-button寫入這兩個(gè)方法,但是elementUI并不支持。 所以我在外面套了一層div

    2024年02月12日
    瀏覽(36)
  • element ui 中在el-table內(nèi),當(dāng)內(nèi)容超過多少行時(shí),顯示el-tooltip

    最近來了一個(gè)需求,在一個(gè)el-table里邊的某一列渲染一個(gè) ‘介紹’ 的內(nèi)容,由于內(nèi)容過多,全部展示顯示的不是很美觀,所以就給定了個(gè)需求讓超出兩行后顯示省略號(hào),并在鼠標(biāo)移上去之后顯示全部內(nèi)容。 我首先想到的就是使用el-tooltip來實(shí)現(xiàn),但是在使用過程中試了很多方

    2024年02月03日
    瀏覽(17)
  • el-table 列的動(dòng)態(tài)顯示與隱藏

    el-table 列的動(dòng)態(tài)顯示與隱藏

    目錄 業(yè)務(wù)場景 官方鏈接 實(shí)現(xiàn)效果圖 使用框架 代碼展示 template代碼 ①、為什么要給el-table綁定【:key=\\\"reload\\\"】? ②、為什么給每個(gè)綁定【key=\\\"Math.random()\\\"】呢? ③、為什么列改變之后要添加【reload = Math.random();】修改值呢? ④、為什么要給el-table定義【max-height】屬性? ⑥、為

    2023年04月18日
    瀏覽(16)
  • 【elementplus】解決el-table開啟show-overflow-tooltip后,tooltip的顯示會(huì)被表格邊框遮擋的問題

    【elementplus】解決el-table開啟show-overflow-tooltip后,tooltip的顯示會(huì)被表格邊框遮擋的問題

    如圖所示: 原因: 1. el-table沒有設(shè)置高度;2.就是被遮住了 解決: 方法一:給el-table設(shè)置高度 方法二: 如果不想給el-table設(shè)置高度,就直接使用方法二解決即可

    2024年02月12日
    瀏覽(72)
  • 【Vue3+element plus 】el-table滾動(dòng)條、固定列fixed、表頭超出內(nèi)容隱藏并顯示省略號(hào)

    【Vue3+element plus 】el-table滾動(dòng)條、固定列fixed、表頭超出內(nèi)容隱藏并顯示省略號(hào)

    ????????element plus中el-table采用的是el-scrollbar,無法采用全局默認(rèn)滾動(dòng)條樣式修改,需要單獨(dú)寫公共樣式。 原生滾動(dòng)條樣式 el-table滾動(dòng)條樣式 效果圖: ????????el-table設(shè)置了自定義樣式后,為el-table-column添加fixed=\\\"right\\\"屬性,此時(shí)表格側(cè)邊欄固定列出現(xiàn)樣式錯(cuò)亂,自定義

    2024年02月12日
    瀏覽(35)
  • 【CSS】鼠標(biāo)(移入/移出)平滑(顯示/隱藏)下劃線

    【CSS】鼠標(biāo)(移入/移出)平滑(顯示/隱藏)下劃線

    鼠標(biāo)移入內(nèi)容時(shí),下劃線從 左 開始繪制到 右 側(cè)結(jié)束 鼠標(biāo)移出內(nèi)容時(shí),下劃線從 左 開始擦除到 右 側(cè)結(jié)束 我們給內(nèi)容添加一個(gè)黑色背景 background: #000; 示例 效果 將黑色背景 background: #000; 替換成彩色漸變背景 background: linear-gradient(to right,#ec695c,#61c454); 示例 效果 寬度設(shè)置100個(gè)

    2024年02月09日
    瀏覽(26)
  • css滾動(dòng)條變細(xì)且隱藏,鼠標(biāo)移入顯示

    全局修改滾動(dòng)條的樣式,讓滾動(dòng)條變細(xì)且隱藏,只有鼠標(biāo)移入到所屬區(qū)域時(shí)才顯示。 滾動(dòng)條可設(shè)置的元素: 元素后面還可以跟一些事件:

    2024年01月19日
    瀏覽(19)
  • Vue中實(shí)現(xiàn)鼠標(biāo)移入顯示,移出隱藏滾動(dòng)條

    Vue中實(shí)現(xiàn)鼠標(biāo)移入顯示,移出隱藏滾動(dòng)條

    實(shí)現(xiàn)目標(biāo):鼠標(biāo)移入顯示滾動(dòng)條,移出隱藏滾動(dòng)條。 1、 html 結(jié)構(gòu)內(nèi)容如下: 注意:文本內(nèi)容需要溢出容器才能顯示滾動(dòng)條。 代碼說明: 2、 css 樣式: 注意:該樣式存在兼容性問題,只在以 webkit 為內(nèi)核的瀏覽器才可使用。 3、 js 功能實(shí)現(xiàn): 4、效果演示 補(bǔ)充:實(shí)現(xiàn)隱藏滾

    2024年04月22日
    瀏覽(87)
  • vue鼠標(biāo)移入顯示彈窗,移出隱藏彈窗,記錄一下

    vue鼠標(biāo)移入顯示彈窗,移出隱藏彈窗,記錄一下

    鼠標(biāo)移入A彈出B , 移出A隱藏B, A : B :? 邏輯 :

    2024年02月04日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包