ie瀏覽器下滾動條問題
眾所周知,原始瀏覽器滾動條不美觀,所以重新修改樣式,但在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屬性)
}
}