html更改offset,javascript - HTML offsetLeft delays to change - Stack Overflow

I have four canvas in my screen, positioned two above and two below.

Each one have a button that makes possible to maximize the canvas, hiding the others.

This button is positioned above each canvas, with absolute position based on offsetTop and offsetLeft of the canvas.

However, when I maximize or minimize a canvas, the button formula updates only the width property.

The strange thing is that if I resize the screen, which also calls resize function, everything goes to the right place.

Ci159.jpg

RuJIQ.jpg

REPFv.jpg

EDIT: Additional information: I am using VueJS and, in order to hide the other canvas, I apply v-show="false" to them parent divs, which only applies display: none.

Some snippets:

Initial resize and listener:

window.onload = function () {

resizeAll();

window.addEventListener('resize', resizeAll, false);

};

The resize hub:

function resizeAll () {

vue.$refs.panelOne.resizeDefault();

// ...

vue.$refs.panelN.resizeDefault();

}

The panel's resize default and resize method. The "expandStyles" is the css styles applied to the button:

resizeDefault() {

let dimensions;

if (this.expanded) {

dimensions = getScreenDimensions();

} else {

dimensions = getHalfScreenDimensions();

}

this.resize(dimensions.width, dimensions.height);

}

resize (width, height) {

this.canvas.width = width;

this.canvas.height = height;

this.expandStyles.top = (this.canvas.offsetTop + 10) + 'px';

this.expandStyles.left = (this.canvas.offsetLeft + this.canvas.width - 40) + 'px';

drawInterface.redraw();

}

And finally, the dimension getters:

function getScreenDimensions () {

return {

width: window.innerWidth - 310,

height: window.innerHeight * 0.92

};

}

function getHalfScreenDimensions () {

return {

width: (window.innerWidth - 310) / 2,

height: (window.innerHeight * 0.92) / 2

};

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值