修复JS的兼容性问题

master
落雨楓 2 years ago
parent 70fbbb3641
commit 7b57ec5134

@ -1,23 +1,41 @@
var offsetSize = (function() {
if (mw.config.get('skin') === 'timeless') {
if (mw.config.get('skin') === 'timeless' && window.innerWidth > 850) {
return 55;
} else if (mw.config.get('skin') === 'minerva') {
return 56;
} else {
return 0;
}
})();
var scrollBehaviorAvaliable = (function() {
// 检测Chrome
var v = navigator.userAgent.match(/Chrome\/(?<version>\S+)/);
if (v && v.groups.version) { // 检测chrome版本
if (v && v.groups.version) {
var chromeVersion = parseInt(v.groups.version);
return chromeVersion >= 61;
} else { // 非chrome
return true;
}
// 检测Firefox
v = navigator.userAgent.match(/Firefox\/(?<version>\S+)/);
if (v && v.groups.version) {
var firefoxVersion = parseInt(v.groups.version);
return firefoxVersion >= 36;
}
// 检测Safari
v = navigator.userAgent.match(/Version\/(?<version>\S+)/);
if (v && v.groups.version) { // Safari
var safariVersion = parseFloat(v.groups.version);
return safariVersion >= 14;
}
return false;
})();
function scrollToAnchor(link){
var target = $(link.replace(/\./g, '\\.'));
if(target.length > 0){
var el = document.getElementById(link.replace(/^#/, ''));
if (el) {
var target = $(el);
target.click(function(){ return false; });
var position = target.offset().top - offsetSize;
if (scrollBehaviorAvaliable) {

Loading…
Cancel
Save