pc zoom缩放js实现代码
1.vue中可使用window.onload = function() {document.body.style.zoom = "normal"; //避免zoom尺寸叠加let scale = document.body.clientWidth / 1904;document.body.style.zoom = scale;}...
·
1.vue中可使用
window.onload = function() {
document.body.style.zoom = "normal"; //避免zoom尺寸叠加
let scale = document.body.clientWidth / 1904;
document.body.style.zoom = scale;
};
//防抖,避免resize占用过多资源
(function() {
var throttle = function(type, name, obj) {
obj = obj || window;
var running = false;
var func = function() {
if (running) {
return;
}
running = true;
requestAnimationFrame(function() {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
obj.addEventListener(type, func);
};
throttle("resize", "optimizedResize");
})();
window.addEventListener("optimizedResize", function() {
document.body.style.zoom = "normal";
let scale = document.body.clientWidth / 1904;
document.body.style.zoom = scale;
});
2.jquery中可用
$(window).resize(function() {
$("body").css("zoom", $(window).width() / 1440);
});
$("body").css("zoom", $(window).width() / 1440);
更多推荐
已为社区贡献1条内容
所有评论(0)