refactor(pake): Simplify the zoomIn and zoomOut

This commit is contained in:
pan93412
2022-11-08 16:55:08 +08:00
parent e333cf1297
commit cd84fe57bc

View File

@@ -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)}%`
); );
} }