在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>



(全文完)


以下为广告部分

您部署的HTTPS网站安全吗?

如果您想看下您的网站HTTPS部署的是否安全,花1分钟时间来 myssl.com 检测以下吧。让您的HTTPS网站变得更安全!

SSL检测评估

快速了解HTTPS网站安全情况。

安全评级(A+、A、A-...)、行业合规检测、证书信息查看、证书链信息以及补完、服务器套件信息、证书兼容性检测等。

SSL证书工具

安装部署SSL证书变得更方便。

SSL证书内容查看、SSL证书格式转换、CSR在线生成、SSL私钥加解密、CAA检测等。

SSL漏洞检测

让服务器远离SSL证书漏洞侵扰

TLS ROBOT漏洞检测、心血漏洞检测、FREAK Attack漏洞检测、SSL Poodle漏洞检测、CCS注入漏洞检测。

原文地址:https://www.cnblogs.com/zhuqil/p/1641565.html