模仿网易彩票网(http://caipiao.163.com/)的登陆框自己做了一个拖动层,不过有点小问题——在谷歌浏览拖动的时候鼠标状态变成了文字状态(cursor:text;)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js拖动层</title>
<style>
body{padding:0; margin:0; width:100%; height:100%;}
* html,* html body{background-image:url(about:blank);background-attachment:fixed}
#dragWp{width:100%; height:100%; position:fixed; left:0; top:0; z-index:99999999; _position:absolute;_left:expression(eval(document.documentElement.scrollLeft));_top:expression(eval(document.documentElement.scrollTop))}
#dragBg{ width:100%; height:100%; background-color:#000; position:absolute; left:0; top:0; opacity:0.4; filter:alpha(opacity=40);}
#dragMain{width:200px;height:100px;position:absolute; border:1px solid #999;line-height:30px;font-size:16px;text-align:center; background-color:#FFF;}
#dragTitle{ width:100%; height:40px; line-height:40px; background-color:#ccc; cursor:move;}
#close{float:right; margin-right:5px; z-index:999; font-size:12px; font-style:normal; cursor:pointer;}
</style>
</head>
<body>
<div style="height:1200px; text-align:center;">
<h1>hello world</h1>
</div>
<div id="dragWp">
<div id="dragBg"></div>
<div id="dragMain">
<div id="dragTitle">
<em id="close">关闭</em>拖动层
</div>
hello world
</div>
</div>
<script>
window.onload=function(){
var dragWp=document.getElementById("dragWp");
var dragMainId=document.getElementById("dragMain");
var w=dragWp.offsetWidth;
var h=dragWp.offsetHeight;
dragMainId.style.left=(w-dragMainId.offsetWidth)/2+"px";
dragMainId.style.top=(h-dragMainId.offsetHeight)/2+"px";
} function dragTemp(dragWp,dragMainId,dragTitleId,closeId,opacity){
var dragWp=document.getElementById(dragWp);
var dragMainId=document.getElementById(dragMainId);
var dragTitleId=document.getElementById(dragTitleId);
var closeId=document.getElementById(closeId);
var posX,posY,x,y;
dragTitleId.onmousedown=function(e){
var e = e || window.event;
posX=e.clientX-dragMainId.offsetLeft; //鼠标距离拖动层左侧的距离
posY=e.clientY-dragMainId.offsetTop; //鼠标距离拖动层上侧的距离
dragMainId.style.opacity=opacity;
dragMainId.style.filter="alpha(opacity="+opacity*100+")";
document.onmousemove=function(e){
var e = e || window.event;
x=e.clientX-posX;
y=e.clientY-posY;
// if(x<=0) x=0; //不允许移出左边
// else if(x>=document.body.clientWidth-dragMainId.offsetWidth) x=document.body.clientWidth-dragMainId.offsetWidth; //不允许移出右边
dragMainId.style.left=x+"px";
dragMainId.style.top=y+"px";
dragTitleId.style.cursor="move";
document.onselectstart=function(){ return false } //拖动不选中文字
}
};
document.onmouseup=function(){
document.onmousemove=null;
dragMainId.style.opacity=1;
dragMainId.style.filter="alpha(opacity=100)";
}
if(closeId){
closeId.onclick=function(){
dragWp.style.display="none";
}
}
}
function drag(args){
dragTemp(args.dragWp,
args.dragMainId,
args.dragTitleId,
args.closeId || null,
args.opacity || 1)
}
//调用
drag({dragWp:"dragWp",dragMainId:"dragMain",dragTitleId:"dragTitle",closeId:"close",opacity:0.5});
</script>
</body>
</html>

js拖动层的更多相关文章

  1. js拖动层原形版

    脚本文件: function JzDrag(moveDivId, moveDivHandle) { // var me = this; this.M = false; //是否在移动对象 this.D ...

  2. JQuery 拖动层

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  3. JS拖动DIV布局

    方法一: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  4. 在chrome下鼠标拖动层变文本形状的问题

    学JQ也有一段时间了,想自己写个鼠标拖动层移动的效果(很简单,只是为了练习而已)于是就写下了下面的代码 <!DOCTYPE html> <html> <head> ...

  5. h5滑动方向、手机拖动层

    做h5时需对手指滑动方向判断及拖动浮动层,本文代码适用于手机端h5页面,pc页面可使用onMouseDown.onMouseUp.onMouseMove.(本方法仅为功能实现原理和演示,可根据自己的需 ...

  6. 微信小程序-06-详解介绍.js 逻辑层文件-注册页面

    上一篇介绍的是 app.js 逻辑层文件中注册程序,对应的每个分页面都会有的 js 文件中 page() 函数注册页面 微信小程序-06-详解介绍.js 逻辑层文件-注册页面 宝典官方文档: http ...

  7. 微信小程序-05-详解介绍.js 逻辑层文件

    上一篇介绍了关于.json 的配置文件,本篇介绍关于.js 逻辑层文件 微信小程序-05-详解介绍.js 逻辑层文件 宝典官方文档: https://developers.weixin.qq.com/ ...

  8. JS 拖动原理

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 拖动层 拖动div 封装js 貌似不兼容FF,郁闷

    原文发布时间为:2009-12-02 -- 来源于本人的百度文章 [由搬家工具导入] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tran ...

随机推荐

  1. C程序设计语言练习题1-21

    练习1-21 编写程序entab,将空格串替换为最少数量的制表符和空格,但要保持单词之间的间隔不变.假设制表符终止的位置与练习1-20的detab程序的情况相同.当使用一个制表符或者一个空格都可以打到 ...

  2. iOS7——图像资源Images Assets

    iOS7初体验(3)——图像资源Images Assets 分类: iOS开发2013-06-18 16:02 17583人阅读 评论(2) 收藏 举报 ios7Images xcassets图像资源 ...

  3. 转:QT 的点点滴滴 错误总结

    转自:http://blog.csdn.net/lbsljn/archive/2009/12/29/5099590.aspx MinGw + CodeBlock + QT4.5 类定义后面要加&quo ...

  4. 父Prefab与子prefab问题

    PrefabRevolution 原文:http://framebunker.com/blog/poor-mans-nested-prefabs/   (溜还是老外溜啊) 有些时候需要在Prefab里 ...

  5. 禁用USB存储设备(不重启)

    Title:禁用USB存储设备(不重启) -- 2012-09-13 12:08 在win2003实验,USB存储禁止,无需重启! stop usbrw.reg ------------------- ...

  6. hdu 1543 Paint the Wall

    http://acm.hdu.edu.cn/showproblem.php?pid=1543 #include <cstdio> #include <cstring> #inc ...

  7. ural 1333 Genie Bomber 2

    #include <cstdio> #include <cstring> #include <algorithm> #define maxn 200 using n ...

  8. Activity大致会经过如下四个状态

    1.活动主题:当前Activity位于前台,用户可见,可以获得焦点.2.暂停状态:其他Activity位于前台,该Activity依然可见,只是不能获得焦点.3.停止状态:该Activity不可见,失 ...

  9. Qt之QTableView显示富文本(使用了QAbstractTextDocumentLayout和QTextDocument)

    http://blog.csdn.net/liang19890820/article/details/50973099

  10. QT文档如何使用

    http://blog.csdn.net/chenlong12580/article/details/7389588