div层可拖动为什么没反应,求大神指导??? 5
css里面:#set_BgImage{width:600px;height:600px;border:1pxsolid#FA9F22;margin:0pxauto;bor...
css里面:
#set_BgImage {
width:600px;
height:600px;
border:1px solid #FA9F22;
margin:0px auto;
border-radius:10px;
position:absolute;
}
.set_Head1 {
width:600px;
height:50px;
background-color:#FA9F22;
border:1px solid #FA9F22;
border-radius:10px;
cursor:pointer;
position:absolute;
}
JS里面:
var a;
document.onmouseup = function () {
if (!a) return;
document.all ? a.releaseCapture() : window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
a = "";
};
document.onmousemove = function (d) {
if (!a) return;
if (!d)
d = event;
a.style.left = (d.clientX - b) + "px";
a.style.top = (d.clientY - c) + "px";
};
function Drag(o, e) {
a = o; document.all ? a.setCapture() : window.captureEvents(Event.MOUSEMOVE);
b = e.clientX - parseInt(a.style.left);
c = e.clientY - parseInt(a.style.top);
}
body里面:
<div id="set_BgImage">
<div class="set_Head1" onmousedown="Drag(this,event)"></div>
</div> 展开
#set_BgImage {
width:600px;
height:600px;
border:1px solid #FA9F22;
margin:0px auto;
border-radius:10px;
position:absolute;
}
.set_Head1 {
width:600px;
height:50px;
background-color:#FA9F22;
border:1px solid #FA9F22;
border-radius:10px;
cursor:pointer;
position:absolute;
}
JS里面:
var a;
document.onmouseup = function () {
if (!a) return;
document.all ? a.releaseCapture() : window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
a = "";
};
document.onmousemove = function (d) {
if (!a) return;
if (!d)
d = event;
a.style.left = (d.clientX - b) + "px";
a.style.top = (d.clientY - c) + "px";
};
function Drag(o, e) {
a = o; document.all ? a.setCapture() : window.captureEvents(Event.MOUSEMOVE);
b = e.clientX - parseInt(a.style.left);
c = e.clientY - parseInt(a.style.top);
}
body里面:
<div id="set_BgImage">
<div class="set_Head1" onmousedown="Drag(this,event)"></div>
</div> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询