众所周知,原始浏览器滚动条不美观,所以重新修改样式,但在ie上并不起效果;没有办法,只好寻找插件,来实现;
最终找到的是smooth-scrollbar(但也只能兼容到ie10(11)了且原始要加滚动条的div属性不能是overflow-y:scroll)
方法:
import Scrollbar from 'smooth-scrollbar';//引入自定义滚动条控件
mounted() {
Scrollbar.init(document.querySelector('#popBox'))
},
对于ie9由于没有overflow-y:scroll属性,导致ie9下没有滚动条,只能进行判断了
法一:
index.html中
<!--[if lte IE 9]> IE9以及IE9以下版本可识别
#popBox{
overflow-y:scroll
}
<![endif]-->
第一次使用是可以的,后面再试不行了,只能在js中判断了;
法二:
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 9) {
this.popheight.overflowY = 'scroll'; (popheight为popbox的style属性)
}
}