popupJS.js
2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//当需要关闭弹窗时
function Close() {
var SGWorld = new CreateSGObj();
//获取当前popup的ID
var id = getParamValue("popupID", "");
if (id !== null) {
var popup = SGWorld.ProjectTree.GetObject(id);//根据id获取弹窗对象
SGWorld.Window.RemovePopup(popup);//移除的是popup弹窗对象,不能直接根据id删除对象
}
alert("关闭");
//也可以通过弹窗的标题来删除弹窗
//SGWorld.Window.RemovePopup(popup.Caption);
}
///鼠标左键 在标题部分按住时,表明想要移动弹窗,按住鼠标左键后移动的话,就同时改变弹窗位置
///当鼠标左键弹起时,表明停止移动弹窗
var left = 0, top = 0;
function MouseDown(event) {
var SGWorld = new CreateSGObj();
var popupID = getParamValue("popupID", "");//获取弹窗ID
if (popupID !== "") {
let popup = SGWorld.ProjectTree.GetObject(popupID);//获取弹窗
//获取当前的鼠标位置
var mouseInfo = SGWorld.Window.GetMouseInfo();
//这里是标记 当前鼠标相对于弹窗的左上角所在的位置left和top,这两个值在移动弹窗时,是保持不变的
//然后根据移动后的鼠标位置,减去left和top就是弹窗所在的位置
left = mouseInfo.X - popup.Left;
top = mouseInfo.Y - popup.Top;
}
//添加鼠标左键 按住移动和 左键弹起的事件
//按住移动 OnFrame 弹窗随着移动
//左键弹起 OnLButtonUp 去除相关监听(OnFrame和OnLButtonUp)
SGWorld.AttachEvent("OnFrame", FrameEvent);
}
//鼠标移动的监听事件
function FrameEvent() {
var SGWorld = new CreateSGObj();
//获取移动时的鼠标位置
var mouseInfo = SGWorld.Window.GetMouseInfo();
var popupID = getParamValue("popupID", "");//获取popupID
if (popupID !== "") {
let popup = SGWorld.ProjectTree.GetObject(popupID);
//popup.Top //popup.Left
//鼠标位置的X值-坐标左键相对于弹窗位置的X值(left)=弹窗位置的Left值
//鼠标位置的Y值-坐标左键相对于弹窗位置的Y值(top)=弹窗位置的Top值
popup.Left = mouseInfo.X - left;
popup.Top = mouseInfo.Y - top;
}
}
//当鼠标弹起时,说明拖动事件已经结束
function MouseUp(event) {
var SGWorld = new CreateSGObj();
SGWorld.DetachEvent("OnFrame", FrameEvent);
}