下面的是鼠标拖拽图片的代码,怎么加代码才可以让鼠标点击1秒后才允许移动图片呢?
据说是用setTimeout来解决 ..但是具体的不会啊..求解 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title>无标题文档</title>
<style></style>
<head></head>
<SCRIPT language=JavaScript> 
drag = 0 
move = 0 
var ie=document.all; 
var nn6=document.getElementById&&!document.all; 
var isdrag=false; 
var y,x; 
var oDragObj; 
function moveMouse(e) { 
if (isdrag) { 
oDragObj.style.top = (nn6 ? nTY + e.clientY - y : nTY + event.clientY - y)+"px"; 
oDragObj.style.left = (nn6 ? nTX + e.clientX - x : nTX + event.clientX - x)+"px"; 
return false; 


function initDrag(e) { 
var oDragHandle = nn6 ? e.target : event.srcElement; 
var topElement = "HTML"; 
while (oDragHandle.tagName != topElement && oDragHandle.className != "dragAble") { 
oDragHandle = nn6 ? oDragHandle.parentNode : oDragHandle.parentElement; 

if (oDragHandle.className=="dragAble") { 
isdrag = true; 
oDragObj = oDragHandle; 
nTY = parseInt(oDragObj.style.top+0); 
y = nn6 ? e.clientY : event.clientY; 
nTX = parseInt(oDragObj.style.left+0); 
x = nn6 ? e.clientX : event.clientX; 
document.onmousemove=moveMouse; 
return false; 


document.onmousedown=initDrag; 
document.onmouseup=new Function("isdrag=false"); </script>
<div id='block1'  onmouseout='drag=0' onmouseover='dragObj=block1; drag=1;' style='z-index:0; left:0px; top:0px; width:0px; height:0px; 
     position: absolute' class="dragAble">
<img src="http://pic10.nipic.com/20100926/2874022_122448725818_2.jpg" >
</div>
</html>下面的是鼠标点击一秒后加边框的代码 参考了很久...改不进去啊<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title>JS+CSS给图片加上鼠标滑过的方框</title>
<style>
    .borderimage
    {
        border: 5px solid #ffffff;
    }
</style>
<script language="JavaScript">
    var v;
    function borderit(which, color) {
        //if IE 4+ or NS 6+
        if (document.all || document.getElementById) {
            which.style.borderColor = color;
        }
    }
    function _borderit(which, color) {
        return function () {
            borderit(which, color);
        }
     }
    function myfunction(which, color) {        v = setTimeout(_borderit(which,color), 500);
    };
    function stopfunction(which, color) {
        clearTimeout(v); 
        borderit(which, color); 
    }
</script>
<div>
    <img src="http://pic10.nipic.com/20100926/2874022_122448725818_2.jpg" class="borderimage"
        onmousedown="myfunction(this,'#1c1c1c')" onmouseup="stopfunction(this,'white')">
</div>
</html>

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <title>无标题文档</title>
    <style></style>
    <head></head>
    <SCRIPT language=JavaScript> 
    drag = 0 
    move = 0 
    var ie=document.all; 
    var nn6=document.getElementById&&!document.all; 
    var isdrag=false; 
    var y,x; 
    var oDragObj; 
    var timer;
    function moveMouse(e) { 
        if (isdrag) { 
            oDragObj.style.top = (nn6 ? nTY + e.clientY - y : nTY + event.clientY - y)+"px"; 
            oDragObj.style.left = (nn6 ? nTX + e.clientX - x : nTX + event.clientX - x)+"px"; 
            return false; 
        } 

    function initDrag(e) { 
        var oDragHandle = nn6 ? e.target : event.srcElement; 
        var topElement = "HTML"; 
        while (oDragHandle.tagName != topElement && oDragHandle.className != "dragAble") { 
            oDragHandle = nn6 ? oDragHandle.parentNode : oDragHandle.parentElement; 
        } 
        if (oDragHandle.className=="dragAble") {
    timer = setTimeout(function(){
    oDragHandle.style.border = '11px solid #000';
    }, 500)
            isdrag = true; 
            oDragObj = oDragHandle; 
            nTY = parseInt(oDragObj.style.top+0); 
            y = nn6 ? e.clientY : event.clientY; 
            nTX = parseInt(oDragObj.style.left+0); 
            x = nn6 ? e.clientX : event.clientX; 
            document.onmousemove=moveMouse; 
            return false; 
        } 

    document.onmousedown = initDrag; 
    document.onmouseup= function(){
    isdrag=false;
    if(timer) clearTimeout(timer);
    oDragObj.style.borderColor = '#fff';
    }; </script>
    <div id='block1' style='position: absolute' class="dragAble">
    <img src="http://pic10.nipic.com/20100926/2874022_122448725818_2.jpg" >
    </div>
    </html>
    这个意思?