修复兼容模式

master
落雨楓 3 years ago
parent c2d5d2359b
commit 132feeb955

File diff suppressed because one or more lines are too long

@ -1,4 +1,4 @@
@globalTransition: background-color 250ms linear;
@globalTransition: opacity 250ms linear, background-color 250ms linear;
@globalBgColor: rgba(252, 252, 252, 0.8);
@globalBgLoadingColor: rgba(252, 252, 252, 1);
@backdropFilter: saturate(120%) blur(20px);
@ -21,4 +21,14 @@
.breadcrumb {
background-color: rgba(255,255,255,0.6);
}
&.bgimg-fallback {
.bgimg-background-blur {
background: var(--bgimg-blur-image), var(--bgimg-overlay-color, @globalBgColor) !important;
background-blend-mode: saturation !important;
background-attachment: fixed !important;
background-size: var(--bgimg-bg-size) !important;
background-position: var(--bgimg-bg-pos) !important;
}
}
}

@ -1,8 +1,9 @@
@globalRadius: 0.4em;
@globalBgColor: rgba(252, 252, 252, 0.8);
@globalBgColor: rgba(252, 252, 252, 1);
@globalBgLoadingColor: rgba(252, 252, 252, 1);
@headerBgColor: rgba(252, 252, 252, 0.8);
@footerBgColor: rgba(255, 255, 255, 0.75);
@contentBgColor: rgba(252, 252, 252, 0.5);
@headerBgColor: rgba(255, 255, 255, 0.65);
@footerBgColor: transparent;
@globalBoxShadow: 0 3px 5px -1px rgba(0,0,0,.2),0 5px 8px 0 rgba(0,0,0,.14),0 1px 14px 0 rgba(0,0,0,.12);
@backdropFilter: saturate(120%) blur(20px);
@globalTransition: opacity 250ms linear, background-color 250ms linear;
@ -29,26 +30,14 @@
.header-container.header-chrome {
background-color: @headerBgColor;
position: relative;
&.bgimg-background-loading {
background-color: @globalBgLoadingColor;
}
}
.minerva-footer {
background-color: @footerBgColor;
position: relative;
&.bgimg-background-loading {
background-color: @globalBgLoadingColor;
}
}
#content {
background-color: @globalBgColor;
&.bgimg-background-loading {
background-color: @globalBgLoadingColor;
}
background-color: @contentBgColor;
}
}

@ -4,10 +4,10 @@
@headerBgColor: transparent;
@footerBgColor: rgba(149, 149, 149, 0.7);
@footerBgLoadingColor: rgba(149, 149, 149, 1);
@globalBoxShadow: 0 3px 5px -1px rgba(0,0,0,.2),0 5px 8px 0 rgba(0,0,0,.14),0 1px 14px 0 rgba(0,0,0,.12);
@globalBoxShadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2),
0 5px 8px 0 rgba(0, 0, 0, 0.14), 0 1px 14px 0 rgba(0, 0, 0, 0.12);
@backdropFilter: saturate(120%) blur(20px);
@globalTransition: opacity 250ms linear, background-color 250ms linear;
@headerBlurDepth: 10px;
.has-bgimg {
.isekai-bgimg {
@ -98,15 +98,8 @@
border-bottom-right-radius: 0;
border: none;
background: none;
backdrop-filter: none;
box-shadow: none;
&::before {
background: none;
}
&::after {
display: none;
}
}
#mw-content-block {
@ -122,14 +115,16 @@
}
}
#mw-header-nav-hack {
background: rgba(255,255,255,0.5);
}
#mw-header-hack {
z-index: 99;
}
#mw-site-navigation .sidebar-chunk,
#mw-related-navigation .sidebar-chunk {
background: none;
backdrop-filter: none;
}
.isekai-bgimg {
display: none;
}
@ -155,16 +150,8 @@
}
}
@media screen and (max-width: 1099px) {
#mw-site-navigation .sidebar-chunk,
#mw-related-navigation .sidebar-chunk {
&::after {
display: none;
}
}
}
.comment-body textarea, .comment-preview {
.comment-body textarea,
.comment-preview {
background: @globalBgColor;
&.bgimg-background-loading {
@ -179,4 +166,35 @@
background-color: @globalBgLoadingColor;
}
}
&.bgimg-fallback {
#mw-content-container {
background: none !important;
}
#mw-footer-container {
--bgimg-overlay-color: @footerBgColor;
}
@media screen and (max-width: 1099px) {
#mw-content {
background: none !important;
}
#mw-content-container {
background: var(--bgimg-blur-image), var(--bgimg-overlay-color, @globalBgColor) !important;
background-blend-mode: saturation !important;
background-attachment: fixed !important;
background-size: var(--bgimg-bg-size) !important;
background-position: var(--bgimg-bg-pos) !important;
}
}
@media screen and (max-width: 1099px) {
#mw-site-navigation .sidebar-chunk,
#mw-related-navigation .sidebar-chunk {
background: none !important;
}
}
}
}

@ -1,7 +1,7 @@
import * as StackBlur from './stackblur';
class BgImage {
constructor(){
constructor() {
this.loaded = false;
this.isCrosBlocked = false;
@ -18,10 +18,7 @@ class BgImage {
}
});
this.domStyles = $('head').append('<style data-type="bgimg-styles"></style>').find('style[data-type="bgimg-styles"]');
this.posStyles = $('head').append('<style data-type="bgimg-styles-pos"></style>').find('style[data-type="bgimg-styles-pos"]');
this.domStyleSheet = this.domStyles[0].sheet;
this.posStyleSheet = this.posStyles[0].sheet;
this.domStyle = document.documentElement.style;
this.hasBlurArea = false;
this.blurRadius = 20;
@ -76,10 +73,10 @@ class BgImage {
return featureSupport;
}
async loadImage(src, xCenter, yCenter){
async loadImage(src, xCenter, yCenter) {
try {
await fetch(src);
} catch(e){
} catch (e) {
this.isCrosBlocked = true;
this.img.crossOrigin = null;
}
@ -91,7 +88,7 @@ class BgImage {
this.img.src = src;
}
generateBlurImage(){
generateBlurImage() {
return new Promise((resolve, reject) => {
let canvas = document.createElement('canvas');
canvas.width = this.img.width;
@ -107,11 +104,11 @@ class BgImage {
});
}
async onImageLoaded(){
async onImageLoaded() {
this.imgRatio = this.img.width / this.img.height;
if(this.hasBlurArea && !this.cssFeature.backdropFilter) { // 不支持backdrop-filter使用js生成模糊
if(!this.isCrosBlocked){
if (this.hasBlurArea && !this.cssFeature.backdropFilter) { // 不支持backdrop-filter使用js生成模糊
if (!this.isCrosBlocked) {
//生成模糊的图片
//css会有白边为了效果好只能用canvas生成了
await this.generateBlurImage();
@ -122,7 +119,7 @@ class BgImage {
this.fixPosition();
if(!this.loaded){
if (!this.loaded) {
this.viewports.forEach((viewport) => {
viewport.css({
backgroundImage: "url('" + this.source + "')",
@ -136,31 +133,30 @@ class BgImage {
});
if (!this.cssFeature.backdropFilter) {
var css = ".has-bgimg .bgimg-background-blur { ";
css += "background-image: url('" + this.blurSource + "'); ";
css += ";";
this.domStyleSheet.insertRule(css, this.domStyleSheet.rules.length);
$('body').addClass('bgimg-fallback');
this.domStyle.setProperty('--bgimg-blur-image', `url('${this.blurSource}')`);
}
this.loaded = true;
}
}
onWindowResize(){
if(this.loaded) this.fixPosition();
onWindowResize() {
if (this.loaded) this.fixPosition();
}
getOverflowSize(screenSize, imgSize, centerPoint){
getOverflowSize(screenSize, imgSize, centerPoint) {
let centerPointPx = imgSize * centerPoint / 100;
let maxOverflow = imgSize - screenSize;
let absOffset = centerPointPx - (screenSize / 2);
return Math.max(0, Math.min(maxOverflow, absOffset));
}
fixPosition(){
fixPosition() {
let screenRatio = window.innerWidth / window.innerHeight;
//计算出适合的大小以及offset
if(this.imgRatio > screenRatio){ //窄屏
if (this.imgRatio > screenRatio) { //窄屏
//图片高度 = 屏幕高度,横向靠近中心点
this.imgSize.height = window.innerHeight;
this.imgSize.width = this.imgSize.height * this.imgRatio;
@ -176,7 +172,7 @@ class BgImage {
this.fixViewportPosition();
}
fixViewportPosition(){
fixViewportPosition() {
this.viewports.forEach((viewport) => {
//设置viewport的style
viewport.css({
@ -185,24 +181,19 @@ class BgImage {
});
});
if(this.hasBlurArea){
if (this.hasBlurArea && !this.cssFeature.backdropFilter) {
//设置模糊背景的style
let css = ".has-bgimg .bgimg-background-blur { ";
css += 'background-size: ' + this.imgSize.width + 'px ' + this.imgSize.height + 'px; ';
css += 'background-position: ' + this.imgOffset.left + 'px ' + this.imgOffset.top + 'px; ';
css += '}';
this.posStyleSheet.insertRule(css, this.posStyleSheet.rules.length);
if(this.posStyleSheet.rules.length > 1) this.posStyleSheet.deleteRule(this.posStyleSheet.rules.length - 2);
this.domStyle.setProperty('--bgimg-bg-size', `${this.imgSize.width}px ${this.imgSize.height}px`);
this.domStyle.setProperty('--bgimg-bg-pos', `${this.imgOffset.left}px ${this.imgOffset.top}px`);
}
}
addViewport(element){
addViewport(element) {
element.css('opacity', 0);
this.viewports.push(element);
}
addBlurBackground(element){
addBlurBackground(element) {
let classList = ['bgimg-background-blur', 'bgimg-background-loading'];
if (this.cssFeature.backdropFilter) {
classList.push('bgimg-backdrop-blur');
@ -213,7 +204,7 @@ class BgImage {
}
}
if(!global.isekai){
if (!global.isekai) {
global.isekai = {};
}
global.isekai.BgImage = BgImage;

Loading…
Cancel
Save