gojs拖动窗口缩放后自动居中对齐

问题描述

因为GoJS开启了可以拖动和缩放后,在窗口大小充足的情况下,默认不会进行自动居中对齐的,需求是在浏览器窗口缩小和最大化时,GoJS中的元素能居中对齐。

解决方法

在鼠标移动事件中添加一下代码

document.onmousemove = function (e) {
    
    
   myDiagram.contentAlignment = go.Spot.Center;
   myDiagram.alignDocument(go.Spot.Center, go.Spot.Center);
   myDiagram.contentAlignment = go.Spot.Default;
}; 

先将contentAlignment设置为Center,再调用alignDocument方法让元素在document和viewport中都居中,然后再将contentAlignment改为Default。

参考文章:https://www.zhangbj.com/p/978.html

猜你喜欢

转载自blog.csdn.net/YG_zhh/article/details/128792171