refactor(pake): Simplify the zoomIn and zoomOut
This commit is contained in:
@@ -154,22 +154,22 @@ function setDefaultZoom() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoomCommon(callback) {
|
function zoomCommon(zoomRule) {
|
||||||
const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%';
|
const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%';
|
||||||
const html = document.getElementsByTagName('html')[0];
|
const html = document.getElementsByTagName('html')[0];
|
||||||
const zoom = callback(htmlZoom);
|
const zoom = zoomRule(htmlZoom);
|
||||||
html.style.zoom = zoom;
|
html.style.zoom = zoom;
|
||||||
window.localStorage.setItem('htmlZoom', zoom);
|
window.localStorage.setItem('htmlZoom', zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoomIn() {
|
function zoomIn() {
|
||||||
zoomCommon((htmlZoom) =>
|
zoomCommon((htmlZoom) =>
|
||||||
parseInt(htmlZoom) < 200 ? parseInt(htmlZoom) + 10 + '%' : '200%',
|
`${Math.min(parseInt(htmlZoom) + 10, 200)}%`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoomOut() {
|
function zoomOut() {
|
||||||
zoomCommon((htmlZoom) =>
|
zoomCommon((htmlZoom) =>
|
||||||
parseInt(htmlZoom) > 30 ? parseInt(htmlZoom) - 10 + '%' : '30%',
|
`${Math.max(parseInt(htmlZoom) - 10, 30)}%`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user