✨ 快捷键支持缩放页面
This commit is contained in:
@@ -85,6 +85,16 @@ window.addEventListener('DOMContentLoaded', (_event) => {
|
||||
if (event.key === "r" && event.metaKey){
|
||||
window.location.reload();
|
||||
}
|
||||
if (event.key === "-" && event.metaKey){
|
||||
zoomOut();
|
||||
}
|
||||
if (event.key === "=" && event.metaKey){
|
||||
zoomIn();
|
||||
}
|
||||
if (event.key === "0" && event.metaKey){
|
||||
document.getElementsByTagName('html')[0].style.zoom = '100%';
|
||||
window.localStorage.setItem('htmlZoom', '100%');
|
||||
}
|
||||
})
|
||||
|
||||
const pakeLinks = document.links;
|
||||
@@ -92,4 +102,29 @@ window.addEventListener('DOMContentLoaded', (_event) => {
|
||||
pakeLinks[linkIndex].target = '_self';
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
setDefaultZoom();
|
||||
|
||||
function setDefaultZoom() {
|
||||
const htmlZoom = window.localStorage.getItem('htmlZoom');
|
||||
if (htmlZoom) {
|
||||
document.getElementsByTagName('html')[0].style.zoom = htmlZoom;
|
||||
}
|
||||
}
|
||||
|
||||
function zoomIn() {
|
||||
const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%';
|
||||
const html = document.getElementsByTagName('html')[0];
|
||||
const zoom = parseInt(htmlZoom) < 200 ? (parseInt(htmlZoom) + 10 +'%') : '200%';
|
||||
html.style.zoom = zoom;
|
||||
window.localStorage.setItem('htmlZoom', zoom);
|
||||
}
|
||||
|
||||
function zoomOut() {
|
||||
const htmlZoom = window.localStorage.getItem('htmlZoom') || '100%';
|
||||
const html = document.getElementsByTagName('html')[0];
|
||||
const zoom = parseInt(htmlZoom) > 30 ? (parseInt(htmlZoom) - 10 +'%') : '30%';
|
||||
html.style.zoom = zoom;
|
||||
window.localStorage.setItem('htmlZoom', zoom);
|
||||
}
|
||||
Reference in New Issue
Block a user