var curObj = document.elementFromPoint(event.x, event.y);用来获取在(x,y)坐标点上的元素。
event.x, event.y指的就是坐标点。你只要判断一下,curObj 这个对象是否是div_x,就知道这个点在不在这个对象内部了
event.x, event.y指的就是坐标点。你只要判断一下,curObj 这个对象是否是div_x,就知道这个点在不在这个对象内部了
解决方案 »
- 如何获取radio中当前选定值的位置
- gridview导出到excel时去掉commandfield的button
- 关于Microsoft Script Debugger调试工具有时不会显示代码
- 用JavaScript获得屏幕中心的办法?
- 子窗口给父窗口传值问题?
- 大家帮忙,为什么出错,很急,,
- window.location的问题!!!谢谢
- 谁有滚动文字条的特效源程序
- checkbox 如何实现不可以多选?只能选择一个,象radio button那样?
- jquery获取上一节点的值
- 请教:如何用js传值给另一个页面且本页面不改变?
- 自己学做HTML编辑器时遇到的问题,麻烦JS高手进来看看~~
急求!
等待达人!
<head>
<script type="text/javascript">
var y_0,top_0,top;
var isMove = false;
function getFocus(obj)
{
obj.setCapture();
obj.style.zIndex = "100";
obj.style.left = "510px";
top = parseInt(obj.style.top);
top_0 = parseInt(obj.style.top);
y_0 = event.clientY;
isMove = true;
}
function move(obj)
{
if(isMove)
{
var y_1 = event.clientY;
var newTop = top + (y_1 - y_0);
if(newTop >= 100 && newTop <= 350)
obj.style.top = newTop + "px";
if((newTop - top_0) >= 25 || (newTop - top_0) <= -25)
{
var div = document.elementFromPoint("510px",newTop + "px");
if(div)
moveTo(div,obj);
}
}
}
function stopMove(obj)
{
obj.releaseCapture();
isMove = false;
obj.style.zIndex = "0";
obj.style.left = "500px";
obj.style.top = top_0 + "px";
}
function moveTo(div_0,div_1)
{
var t = parseInt(div_0.style.top);
div_0.style.top = t + "px";
top_0 = t;
}
</script>
</head>
<body>
<div id="div_0" style="position:absolute;left:500px;top:100px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:orange;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
1</div>
<div id="div_1" style="position:absolute;left:500px;top:150px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:green;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
2</div>
<div id="div_2" style="position:absolute;left:500px;top:200px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:red;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
3</div>
<div id="div_3" style="position:absolute;left:500px;top:250px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:blue;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
4</div>
<div id="div_4" style="position:absolute;left:500px;top:300px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:pink;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
5</div>
<div id="div_5" style="position:absolute;left:500px;top:350px;height:50px;width:200px;text-align:center;line-height:50px;cursor:move;background-color:gray;z-index:0;"
onMouseDown="getFocus(this)" onMouseUp="stopMove(this)" onMouseMove="move(this)">
6</div>
</body>
</html>
function moveTo(div_0,div_1)
{
var t = parseInt(div_0.style.top);
div_0.style.top = t + "px";
top_0 = t;
}
这段代码有问题吗?你看div_1根本没用到啊