JavaScript:Div层拖动效果

Div层拖动效果图:

实现:

CSS:

View Code
<style>
div
{
position:relative;
}
</style>

JS:

View Code
<script type="text/javascript"> 
var mouseover=true
var xcoor;
var ycoor;
function coordinates()
{

if (event.srcElement.id.indexOf("wishbroad") == 0)
    {
    event.srcElement.style.zIndex = 1000;
    mouseover=true;
    pleft=event.srcElement.style.pixelLeft;
    ptop=event.srcElement.style.pixelTop;
    xcoor=event.clientX;
    ycoor=event.clientY;
    document.onmousemove=moveImage;
    }
}

function moveImage()
{
if (mouseover&&event.button==1)
    {
    event.srcElement.style.pixelLeft=pleft+event.clientX-xcoor;
    event.srcElement.style.pixelTop=ptop+event.clientY-ycoor;
    return false;
    }
}

function mouseup()
{
    event.srcElement.style.zIndex = 1;
    mouseover=false;
}
document.onmousedown=coordinates;
document.onmouseup=mouseup;
</script>

HTML:

View Code
<html>
<head>Div层拖动</head>
<body>
<div id="wishbroad1" style="width:200px; height:100px;border:1px solid black;background:gray;">
中国
</div>
<div id="wishbroad2" style="width:200px; height:100px;border:1px solid red;background:red;">
美国
</div>
<div id="wishbroad3" style="width:200px; height:100px;border:1px solid red;background:green;">
日本
</div>
<div id="wishbroad4" style="width:200px; height:100px;border:1px solid red;background:pink;">
巴西
</div>
</body>
</html>

注:仅供参考。未考虑兼容性,IE9测试通过!谷歌拖不动!其它自测。

CSS:不用js实现的css下拉菜单特效

JavaScript:九种js弹出对话框

常用JavaScript

JavaScript:将Table导出到Excel

JQuery表格隔行背景和突出显示当前行

JQuery随机生成动态竖状条投票结果

JQuery中国省市区无刷新三级联动查询

 

 

 

 

 

 

posted @ 2013-03-12 20:49  张小三、  阅读(2885)  评论(2编辑  收藏  举报