当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 在html页面上拖放移动标签

Javascript
非常不错的 子鼠 滑动图片效果 Javascript+CSS
Mozilla 表达式 __noSuchMethod__
javascript 获取图片颜色
JavaScript 在各个浏览器中执行的耐性
在JavaScript中,为什么要尽可能使用局部变量?
javascript 日历提醒系统( 兼容所有浏览器 )
常用JS代码实例小结
jQuery 插件 将this下的div轮番显示
网页特效从下往上过渡 共享图库_最新图片
由document.body和document.documentElement想到的
JavaScript获取GridView中用户点击控件的行号,列号
jQuery 入门讲解1
百度 popup.js 完美修正版非常的不错
jQuery autocomplete插件修改
jQuery对象和DOM对象相互转化
javascript 人物逼真行走,已完成
基于jQuery图片平滑连续滚动插件
ie 调试javascript的工具
ExtJS 2.0实用简明教程 之Border区域布局
ExtJS 2.0实用简明教程 之Ext类库简介

Javascript 中的 在html页面上拖放移动标签


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 197 ::
收藏到网摘: n/a

在html页面上拖放移动标签,需要的朋友可以参考下。 1、设置标签(如img, div等等)的样式:将position设置为absolute,例如:
<div style="position:absolute" id="move_id" onmousedown="mousedown()" onmouseup="mouseup()">
2、用一个临时元素来记录标签的状态 。将临时元素的display设置为none ,隐藏这个临时元素,这里使用了input 扮演临时元素。值为0表示这个标签没有被移动过。当你的鼠标在这个标签上按下的时候,它的值被设置为1,表示准备拖放和移动。
<input type="text" style="display:none" id="temp_id" value="0">
3、象下面一样设置 <body> :
<body onmousemove="mousemove();">
4、最后看下JavaScript函数了:
代码
复制代码 代码如下:

<script language="javascript" type="text/javascript">
function mousedown()
{
document.getElementById("temp_id").value = "1";
}
function mouseup()
{
document.getElementById("temp_id").value = "0";
document.getElementById("move_id").style.cursor = "default";
}
function mousemove()
{
if (document.getElementById("temp_id").value == "1")
{
document.getElementById("move_id").style.top = event.clientY - 10;
document.getElementById("move_id").style.left = event.clientX - 50;
document.getElementById("move_id").style.cursor = "move";
}
}
</script>