ElementUI之隐藏Scrollbar 组件的使用

1. 使用

main.js

//main.js

import {Scrollbar} from 'element-ui'
Vue.use(Scrollbar)

common.scss

//common.scss

.el-scrollbar{
  height: 100%;
}
.el-scrollbar__wrap{
  overflow: scroll;
  overflow-x:auto
}
.el-scrollbar__bar{
  z-index: 9999;
}

template

//组件  将会出现滚动的内容放到上述标签内就可以了

<template>
	<div style="height: 200px;">
	    <el-scrollbar>
	        <ul>
	            <li v-for="(n, index) in 10" :key="index" style="height: 50px;">文本</li>
	        </ul>
	    </el-scrollbar>
	</div>
</template>
2.源码

index.js

// 源码在node_modules 目录下的 element-ui/packages/scrollbar

// 模块入口index.js,从main导入 scrollbar并提供一个安装方法注册成全局组件

import Scrollbar from './src/main';

/* istanbul ignore next */
Scrollbar.install = function(Vue) {
  Vue.component(Scrollbar.name, Scrollbar);
};

export default Scrollbar;

main.js

// reference https://github.com/noeldelgado/gemini-scrollbar/blob/master/index.js

import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
import scrollbarWidth from 'element-ui/src/utils/scrollbar-width';
import { toObject } from 'element-ui/src/utils/util';
import Bar from './bar';

/* istanbul ignore next */
export default {
  name: 'ElScrollbar',

  components: { Bar },

  props: {
    native: Boolean,
    wrapStyle: {},
    wrapClass: {},
    viewClass: {},
    viewStyle: {},
    noresize: Boolean, // 如果 container 尺寸不会发生变化,最好设置它可以优化性能
    tag: {
      type: String,
      default: 'div'
    }
  },

  data() {
    return {
      sizeWidth: '0',
      sizeHeight: '0',
      moveX: 0,
      moveY: 0
    };
  },

  computed: {
    wrap() {
      return this.$refs.wrap;
    }
  },

  render(h) {
    let gutter = scrollbarWidth();
    let style = this.wrapStyle;

    if (gutter) {
      const gutterWith = `-${gutter}px`;
      const gutterStyle = `margin-bottom: ${gutterWith}; margin-right: ${gutterWith};`;

      if (Array.isArray(this.wrapStyle)) {
        style = toObject(this.wrapStyle);
        style.marginRight = style.marginBottom = gutterWith;
      } else if (typeof this.wrapStyle === 'string') {
        style += gutterStyle;
      } else {
        style = gutterStyle;
      }
    }
    const view = h(this.tag, {
      class: ['el-scrollbar__view', this.viewClass],
      style: this.viewStyle,
      ref: 'resize'
    }, this.$slots.default);
    const wrap = (
      <div
        ref="wrap"
        style={ style }
        onScroll={ this.handleScroll }
        class={ [this.wrapClass, 'el-scrollbar__wrap', gutter ? '' : 'el-scrollbar__wrap--hidden-default'] }>
        { [view] }
      </div>
    );
    let nodes;

    if (!this.native) {
      nodes = ([
        wrap,
        <Bar
          move={ this.moveX }
          size={ this.sizeWidth }></Bar>,
        <Bar
          vertical
          move={ this.moveY }
          size={ this.sizeHeight }></Bar>
      ]);
    } else {
      nodes = ([
        <div
          ref="wrap"
          class={ [this.wrapClass, 'el-scrollbar__wrap'] }
          style={ style }>
          { [view] }
        </div>
      ]);
    }
    return h('div', { class: 'el-scrollbar' }, nodes);
  },

  methods: {
    handleScroll() {
      const wrap = this.wrap;

      this.moveY = ((wrap.scrollTop * 100) / wrap.clientHeight);
      this.moveX = ((wrap.scrollLeft * 100) / wrap.clientWidth);
    },

    update() {
      let heightPercentage, widthPercentage;
      const wrap = this.wrap;
      if (!wrap) return;

      heightPercentage = (wrap.clientHeight * 100 / wrap.scrollHeight);
      widthPercentage = (wrap.clientWidth * 100 / wrap.scrollWidth);

      this.sizeHeight = (heightPercentage < 100) ? (heightPercentage + '%') : '';
      this.sizeWidth = (widthPercentage < 100) ? (widthPercentage + '%') : '';
    }
  },

  mounted() {
    if (this.native) return;
    this.$nextTick(this.update);
    !this.noresize && addResizeListener(this.$refs.resize, this.update);
  },

  beforeDestroy() {
    if (this.native) return;
    !this.noresize && removeResizeListener(this.$refs.resize, this.update);
  }
};
IPv6最大的应用亮点在于海量地址、无状态自动配置和移动IPv6的特性,因此IPv6的应用主要有以下几方面: 视频监控   IPv6带来地址的极大丰富,大量部署网络摄像头成为可能,且可方便地进行管理和控制。通过对IPv6协议的支持,网络摄像终端具有更大生命力。从国外视频监控市场可以看出个人用户同样是视频监控的重要客户,而我国的视频监控主要还集中在行业用户,在个人用户方面有很大的发展潜力。视频监控已经开始展现出蓬勃的生命力,而规模化、可运营的监控网络则为运营商提供了广阔的商机。 智能终端、物联网   随着PDA、智能手机等个人终端联入互联网,越来越多的电子设备都有了联网功能的需求,包括:个人智能终端、工业传感器、自动售货机、汽车等,由此将产生巨大的IP地址的需求。IPv6的“即插即用”的地址分配方式及巨大的地址空间可以满足智能终端的需求。 智能家庭网络   基于CNGI的家庭网络是一个研究的热点。未来家庭网络中会包括智能家电、流媒体应用系统、视频监控系统、家居控制系统等多样化的组件,集通信、娱乐、控制应用于一体。结合IPv6技术可以更方便地实现智能家庭网络的部署。 3G业务   普遍认为IPv6将是发展3G移动通信的必要工具。3G标准制订组织3GPP于2000年5月决定在下一代移动技术中采用IPv6,预计在3G手机上将率先使用IPv6。   从目前国内外的应用情况来看,IPv6业务已经有了很大进展,运营商、设备提供商、科研机构的积极参与使得IPv6向大规模商用迈进。市场是技术最好的驱动力,相信伴随部署和应用的逐步展开,IPv6的优势将在具体应用中得到越来越突出的显现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值