<div ref="viewtools"></div>

// 获取浏览器宽高
var w = window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
var h = window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight;

// 获取div宽高
let divW=this.$refs.viewtools.clientWidth;
let divH=this.$refs.viewtools.clientHeight;

//获取拖动div的位置
let top=this.$refs.viewtools.getBoundingClientRect().top;
let left=this.$refs.viewtools.getBoundingClientRect().left;
let right=this.$refs.viewtools.getBoundingClientRect().right;
let bottom=this.$refs.viewtools.getBoundingClientRect().bottom;
console.log(w,h);
console.log(`top:${top},left:${left},right:${right},bottom:${bottom}`);

// 设置div位置
let positionleft=this.$refs.viewtools.style.left;
let positiontop=this.$refs.viewtools.style.top;
let positionright=this.$refs.viewtools.style.right;
let positionbottom=this.$refs.viewtools.style.bottom;
Logo

前往低代码交流专区

更多推荐