增加一個(gè)自定義滾動條插件:
//插件采用jsx語法,使用前需要安裝vue-jsx插件npm install babel-plugin-syntax-jsx --save-devnpm install babel-plugin-transform-vue-jsx --save-devnpm install babel-helper-vue-jsx-merge-props --save-devnpm install babel-preset-es2015 --save-dev
//更改.babelrc文件{ "presets": [ ["es2015", { "modules": false }], ["env", { "modules": false, "targets": { "browsers": ["> 1%", "last 2 versions", "not ie <= 8"] } }], "stage-2" ], "plugins": ["transform-vue-jsx", "transform-runtime"], "env": { "test": { "presets": ["env", "stage-2"], "plugins": ["istanbul"] } }}//安裝使用插件npm isntall --save easyscroll
//main.js中import EasyScroll from 'easyscroll';Vue.use(EasyScroll);
//滾動條主要參數(shù)myBarOption:{ barColor:"#959595", //滾動條顏色 barWidth:6, //滾動條寬度 railColor:"#eee", //導(dǎo)軌顏色 barMarginRight:0, //垂直滾動條距離整個(gè)容器右側(cè)距離單位(px) barMaginBottom:0, //水平滾動條距離底部距離單位(px) barOpacityMin:0.3, //滾動條非激活狀態(tài)下的透明度 zIndex:"auto", //滾動條z-Index autohidemode:true, //自動隱藏模式 horizrailenabled:true,//是否顯示水平滾動條}//頁面代碼<EasyScrollbar :barOption="myBarOption"> <div> <div> 內(nèi)容 </div> </div></EasyScrollbar><script> data{ return{ data(){ myBarOption:{ barColor:"red" } } } }</script>//后臺搭建代碼參考<template> <div id="app"> <router-view class="frameTop" name="top"/> <router-view class="frameMenu" name="menus"/> <EasyScrollbar class="frameMain" :barOption="myBarOption"> <div class="organization" :style="'height:'+scrollHeight+'px'"> <router-view></router-view> </div> </EasyScrollbar> </div></template><script>export default { data(){ return { scrollHeight: 0, //EasyScrollbar 的直接子元素的高度 myBarOption: { barColor:"#959595", //滾動條顏色 barWidth:6, //滾動條寬度 railColor:"#eee", //導(dǎo)軌顏色 barMarginRight:0, //垂直滾動條距離整個(gè)容器右側(cè)距離單位(px) barMaginBottom:0, //水平滾動條距離底部距離單位(px) barOpacityMin:0.3, //滾動條非激活狀態(tài)下的透明度 zIndex:"auto", //滾動條z-Index autohidemode:true, //自動隱藏模式 horizrailenabled:true,//是否顯示水平滾動條 } } }, created: function() { this.init(); }, methods:{ init: function() { //初始化時(shí)計(jì)算頁面核心模塊得高度,并賦值給 EasyScrollbar 的直接子元素 this.scrollHeight = document.documentElement.clientHeight-50; } }}</script><style>@import "./assets/css/base.css";@import "./assets/css/frame.css";</style>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答