87,916
社区成员
发帖
与我相关
我的任务
分享
/*-------------------------鼠标拖动---------------------*/
var od = document.getElementById("fd");
var dx, dy, mx, my, mouseD;
var odrag;
var isIE = document.all ? true : false;
document.onmousedown = function (e) {
var e = e ? e : event;
if (e.button == (document.all ? 1 : 0)) {
mouseD = true;
}
}
document.onmouseup = function () {
mouseD = false;
odrag = "";
if (isIE) {
od.releaseCapture();
od.filters.alpha.opacity = 100;
}
else {
window.releaseEvents(od.MOUSEMOVE);
od.style.opacity = 1;
}
}
od.onmousedown = function (e) {
odrag = this;
var e = e ? e : event;
if (e.button == (document.all ? 1 : 0)) {
mx = e.clientX;
my = e.clientY;
od.style.left = od.offsetLeft + "px";
od.style.top = od.offsetTop + "px";
if (isIE) {
od.setCapture();
od.filters.alpha.opacity = 50;
}
else {
window.captureEvents(Event.MOUSEMOVE);
od.style.opacity = 0.5;
}
}
}
document.onmousemove = function (e) {
var e = e ? e : event;
if (mouseD == true && odrag) {
var mrx = e.clientX - mx;
var mry = e.clientY - my;
od.style.left = parseInt(od.style.left) + mrx + "px";
od.style.top = parseInt(od.style.top) + mry + "px";
mx = e.clientX;
my = e.clientY;
}
}
<div id="fd" style="position: absolute; width: 550px; height: 200px; z-index: 1;
top: 9px; border: 1px solid #888888; visibility: hidden; left: 5px; background-color: #999999;
overflow-y:auto">
<div id="Div2" style="display: block; font-size: x-large;">
<img alt="Loading" src="images/activity.gif" />正在加载中......
</div>
</div>