鼠标拖动文字
来源:互联网 发布:表达知错的句子 编辑:程序博客网 时间:2024/06/14 23:34
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#p{
width: 200px;
height: 200px;
background: green;
position: absolute;
}
#p2{
width: 200px;
height: 200px;
background: gold;
position: absolute;
top: 200px;
left: 200px;
}
</style>
</head>
<body>
<p id="p">
</p>
<p id="p2"></p>
<script>
window.onload=function(){
var p=document.getElementById("p");
p.onmousedown=function(ev){
var e=window.event || ev;//window.event代表着事件对象的状态。只有在事件发生时生效
//var Myp=document.getElementById("p");
//获取到鼠标点击的位置距离p左侧和顶部边框的距离;
var oX=e.clientX-p.offsetLeft;
var oY=e.clientY-p.offsetTop;
//当鼠标移动,把鼠标的偏移量付给p
document.onmousemove=function(ev){
//计算出鼠标在XY方向上移动的偏移量,把这个偏移量加给p的左边距和上边距,p就会跟着移动
var e=window.event|| ev;
p.style.left=e.clientX-oX+"px";
p.style.top=e.clientY-oY+"px";
}
//当鼠标按键抬起,清除移动事件
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
}
}
var p2=document.getElementById("p2");
p2.onmousedown=function(ev){
var e=window.event || ev;
//var Myp=document.getElementById("p");
//获取到鼠标点击的位置距离p左侧和顶部边框的距离;
var oX=e.clientX-p2.offsetLeft;
var oY=e.clientY-p2.offsetTop;
//当鼠标移动,把鼠标的偏移量付给p
document.onmousemove=function(ev){
//计算出鼠标在XY方向上移动的偏移量,把这个偏移量加给p的左边距和上边距,p就会跟着移动
var e=window.event|| ev;
p2.style.left=e.clientX-oX+"px";
p2.style.top=e.clientY-oY+"px";
}
//当鼠标按键抬起,清除移动事件
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
}
}
}
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#p{
width: 200px;
height: 200px;
background: green;
position: absolute;
}
#p2{
width: 200px;
height: 200px;
background: gold;
position: absolute;
top: 200px;
left: 200px;
}
</style>
</head>
<body>
<p id="p">
</p>
<p id="p2"></p>
<script>
window.onload=function(){
var p=document.getElementById("p");
p.onmousedown=function(ev){
var e=window.event || ev;//window.event代表着事件对象的状态。只有在事件发生时生效
//var Myp=document.getElementById("p");
//获取到鼠标点击的位置距离p左侧和顶部边框的距离;
var oX=e.clientX-p.offsetLeft;
var oY=e.clientY-p.offsetTop;
//当鼠标移动,把鼠标的偏移量付给p
document.onmousemove=function(ev){
//计算出鼠标在XY方向上移动的偏移量,把这个偏移量加给p的左边距和上边距,p就会跟着移动
var e=window.event|| ev;
p.style.left=e.clientX-oX+"px";
p.style.top=e.clientY-oY+"px";
}
//当鼠标按键抬起,清除移动事件
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
}
}
var p2=document.getElementById("p2");
p2.onmousedown=function(ev){
var e=window.event || ev;
//var Myp=document.getElementById("p");
//获取到鼠标点击的位置距离p左侧和顶部边框的距离;
var oX=e.clientX-p2.offsetLeft;
var oY=e.clientY-p2.offsetTop;
//当鼠标移动,把鼠标的偏移量付给p
document.onmousemove=function(ev){
//计算出鼠标在XY方向上移动的偏移量,把这个偏移量加给p的左边距和上边距,p就会跟着移动
var e=window.event|| ev;
p2.style.left=e.clientX-oX+"px";
p2.style.top=e.clientY-oY+"px";
}
//当鼠标按键抬起,清除移动事件
document.onmouseup=function(){
document.onmousemove=null;
document.onmouseup=null;
}
}
}
</script>
</body>
</html>
阅读全文
0 0
- 鼠标拖动文字
- CSS禁止鼠标拖动选择文字
- 取消鼠标拖动选中文字的方法
- 文字横向滚动应用实例(DIV + CSS、鼠标拖动)
- 文字纵向滚动应用实例(DIV + CSS、鼠标拖动)
- 转载:收藏:如何禁用鼠标右键拖动复制文字等
- 鼠标拖动
- 鼠标拖动
- 鼠标拖动
- HTML中输入无限文字的文本框,可以随鼠标拖动大小
- JS——禁止鼠标右键,禁止拖动网页元素,禁止选中文字,禁止复制文本
- 鼠标拖动JavaScript
- 鼠标拖动图片-javascript
- 鼠标拖动DIV
- C# 鼠标拖动图片
- 鼠标拖动Div
- 鼠标拖动控件
- 鼠标拖动控件
- Python学习、机器学习(图像处理)、网络渗透、考研杂记
- HDU6025 Coprime Sequence【前缀GCD+后缀GCD】
- 循环日程表问题
- JAVASE_程序的类型及构成
- 初学Android Studio
- 鼠标拖动文字
- Python爬取网页时的#号是为了区分什么
- AJAX内容
- ConstraintLayout(约束布局)
- Biomechanical Design of the Berkeley Lower
- Sensing Pressure Distribution on a Lower-Limb Exoskeleton
- Android中Fragment的使用
- C# 面向过程 猜拳游戏
- js 开发遇到的问题