Skip to content

Commit 54c69fb

Browse files
feat: add min-window-width param
1 parent 3552f5e commit 54c69fb

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Diff for: src/blur-hash/ci.service.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class CIResponsive {
8282
const { config } = this;
8383
const { baseURL, lazyLoading, presets, devicePixelRatioList } = config;
8484
const imgProps = isImage ? getImageProps(imgNode) : getBackgroundImageProps(imgNode);
85-
const { params, imgNodeSRC, blurHash, isLazyCanceled, sizes, isAdaptive, preserveSize } = imgProps;
85+
const { params, imgNodeSRC, blurHash, isLazyCanceled, sizes, isAdaptive, preserveSize, minWindowWidth } = imgProps;
8686

8787
if (!imgNodeSRC) return;
8888

@@ -100,6 +100,11 @@ export default class CIResponsive {
100100
return;
101101
}
102102

103+
if (window.innerWidth < minWindowWidth && !isImage) {
104+
imgNode.style.backgroundImage = 'none';
105+
return;
106+
}
107+
103108
if (isAdaptive) {
104109
size = getBreakpoint(sizes, presets);
105110
} else {

Diff for: src/common/ci.utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export const getImageProps = (image) => {
9494
export const getBackgroundImageProps = (image) => {
9595
const props = {
9696
...getCommonImageProps(image),
97-
imgNodeSRC: attr(image, 'ci-bg-url') || attr(image, 'data-ci-bg-url') || undefined
97+
imgNodeSRC: attr(image, 'ci-bg-url') || attr(image, 'data-ci-bg-url') || undefined,
98+
minWindowWidth: attr(image, 'ci-min-window-width') || attr(image, 'data-min-window-width') || undefined
9899
};
99100
const params = {
100101
...getParamsFromURL(props.imgNodeSRC || ''),

Diff for: src/low-preview/ci.service.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export default class CIResponsive {
8585
const { config } = this;
8686
const { baseURL, lazyLoading, presets, devicePixelRatioList, minLowQualityWidth } = config;
8787
const imgProps = isImage ? getImageProps(imgNode) : getBackgroundImageProps(imgNode);
88-
const { params, imgNodeSRC, isLazyCanceled, sizes, isAdaptive, preserveSize } = imgProps;
88+
const { params, imgNodeSRC, isLazyCanceled, sizes, isAdaptive, preserveSize, minWindowWidth } = imgProps;
8989

9090
if (!imgNodeSRC) return;
9191

@@ -103,6 +103,11 @@ export default class CIResponsive {
103103
return;
104104
}
105105

106+
if (window.innerWidth < minWindowWidth && !isImage) {
107+
imgNode.style.backgroundImage = 'none';
108+
return;
109+
}
110+
106111
if (isAdaptive) {
107112
size = getBreakpoint(sizes, presets);
108113
} else {

Diff for: src/plain/ci.service.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export default class CIResponsive {
7373
const { config } = this;
7474
const { baseURL, lazyLoading, presets, devicePixelRatioList } = config;
7575
const imgProps = isImage ? getImageProps(imgNode) : getBackgroundImageProps(imgNode);
76-
const { params, imgNodeSRC, isLazyCanceled, sizes, isAdaptive, preserveSize } = imgProps;
76+
const { params, imgNodeSRC, isLazyCanceled, sizes, isAdaptive, preserveSize, minWindowWidth } = imgProps;
7777

7878
if (!imgNodeSRC) return;
7979

8080
const [src, isSVG] = getImgSRC(imgNodeSRC, baseURL);
8181
const lazy = isLazy(lazyLoading, isLazyCanceled, isUpdate);
82-
let size
82+
let size;
8383

8484
if (!isSupportedInBrowser(true)) {
8585
if (isImage) {
@@ -91,6 +91,11 @@ export default class CIResponsive {
9191
return;
9292
}
9393

94+
if (window.innerWidth < minWindowWidth && !isImage) {
95+
imgNode.style.backgroundImage = 'none';
96+
return;
97+
}
98+
9499
if (isAdaptive) {
95100
size = getBreakpoint(sizes, presets);
96101
} else {

0 commit comments

Comments
 (0)