如何利用vuejs指令实现不同分辨率适配?下面编程教程网小编给大家详细介绍一下实现代码!
兼容不同分辨率适配代码
// 缩放指令
import Vue from "vue";
function transformScale(el, options) {
const { target = "width", origin = "top left" } = options;
Vue.nextTick(() => {
// 获取显示区域高宽
const width = window.innerWidth;
const height = window.innerHeight;
el.style.transformOrigin = origin;
if (target === "ratio") {
const scaleX = width / CONF.width;
const scaleY = height / CONF.height;
el.style.transform = `scaleX(${scaleX}) scaleY(${scaleY})`;
} else {
let scaleProportion = 1;
if (target === "width") {
scaleProportion = width / CONF.width;
}
if (target === "height") {
scaleProportion = height / CONF.height;
}
el.style.transform = `scale(${scaleProportion})`;
}
});
}
function inserted(el, binding) {
const options = binding.options || { passive: true };
const callback = () => transformScale(el, binding.value);
window.addEventListener("resize", callback);
callback();
el._onResize = {
callback,
options
};
}
function unbind(el) {
if (!el._onResize) {
return;
}
const { callback } = el._onResize;
window.removeEventListener("resize", callback);
delete el._onResize;
}
export const Scale = {
inserted,
unbind
};
export default Scale;
以上是编程学习网小编为您介绍的“如何利用vuejs指令实现不同分辨率适配”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:如何利用vuejs指令实现不同分辨率适配


猜你喜欢
- css高度塌陷问题的解决方案 2023-12-15
- js中toString方法3个作用 2023-08-08
- table表格自带了哪些css样式 2024-12-13
- 9.css浮动.html 2023-10-27
- vue总结 2023-10-08
- vue文章下载功能实现 2023-10-08
- js判断浏览器的比较全的代码 2024-01-17
- web前端性能优化之合理的优化网站图片可以带来更多的流量 2024-02-04
- 利用递增的数字返回循环渐变的颜色的js代码 2023-12-26
- 清除浮动(clearfix 和 clear)的用法示例介绍 2024-02-05