超简单js可拖动层代码

转自:http://www.111cn.net/js_a/74/js+div+dl.htm

超简单js可拖动层代码

<div onmousedown="Drag(this, event)" style="position:absolute;border:1px solid red;background:pink;width:400px;height:300px;"></div>

<script>

function Drag(o, e){

var e = window.event || e;

var _x = e.offsetX || e.layerX;

var _y = e.offsetY || e.layerY;

document.onmousemove = function(e){

o.style.filter = 'Alpha(opacity=70)';

o.style.opacity = '0.7';

var e = window.event || e;

o.style.left = e.clientX - _x + 'px';

o.style.top = e.clientY - _y + 'px';

}

document.onmouseup = function(e){

document.onmousemove = null;

o.style.filter = o.style.opacity = '';

}

}

</script>

你可能感兴趣的:(.net)