<body id="pid"></body>
<script>
function Drag(pid, cssText, className, divId){
var D = this, P = document.getElementById(pid), div, allowMove, width, height, isFF = navigator.userAgent.toLowerCase().indexOf("firefox"), zIndex = 10;

if(window["zIndex"]){
zIndex = window["zIndex"];
}
div = document.createElement("div");
if(cssText){
div.style.cssText = cssText;
}
if(className){
div.className = className;
}
if(divId){
div.id = divId;
}else{
div.id = "div" + parseInt(Math.random() * 10000) + "" + parseInt(Math.random() * 10000);
}
if(!div.style.left){
div.style.left = "0px";
}
if(!div.style.top){
div.style.top = "0px";
}
if(div.style.position != "absolute"){
div.style.position = "absolute";
}
if(!div.style.zIndex){
div.style.zIndex = ++zIndex;
}
div.onmousedown = function(event){
if(isFF > 0){//FF
window.onmousemove = function(event){
e = event || window.event;
D.move(e);
}
window.onmouseup = function(event){
e = event || window.event;
allowMove = false;
}
}else{
P.onmousemove = function(event){
e = event || window.event;
D.move(e);
}
P.onmouseup = function(event){
e = event || window.event;
allowMove = false;
}
}
e = event || window.event;
D.downUp(e, 1);
}
div.onmouseup = function(event){
e = event || window.event;
D.downUp(e, 0);
}
div.onmousemove = function(event){
e = event || window.event;
D.move(e);
}
P.appendChild(div); this.downUp = function(e, type){
var opacity = 0.5;
if(type){
allowMove = true;
if(window["zIndex"]){
zIndex = window["zIndex"];
}
div.style.zIndex = ++zIndex;
window["zIndex"] = zIndex;
}else{
allowMove = false;
opacity = 1;
}
width = e.clientX - parseInt(div.style.left);
height = e.clientY - parseInt(div.style.top);

if(isFF > 0){
div.style.opacity = opacity;
}else{
div.style.filter = "alpha(opacity=" + (opacity * 100) + ")"; 
}
} this.move = function(e){
if(!allowMove){
return false;
}
div.style.left = e.clientX - width + "px";
div.style.top = e.clientY - height + "px";
}
}function create(){
var cssText = "background: #D5D3EB; width: 150px; height: 100px; border: 0.2cm #CCCCFF solid; cursor: pointer; position: absolute; left: " + parseInt(Math.random() * 1000);
new Drag("pid", cssText);
}
</script>
<input type="button" value="创建" onclick="create()">
在谷歌浏览器中一拖动的过快就闪,高手们帮帮我啊