模仿网易彩票网(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. NVIDIA 显卡温度提示过高,显卡温度高99度怎么办?

    你可能没有在意您的NVIDIA(英伟达)显卡温度,那么你就不会知道显卡温度过高如何导致的呢?也不会知道如果去解决显卡温度过高的问题了,在此我希望在电脑玩游戏或者在办公中电脑速度快慢,或者发热的情况下, ...

  2. Centos7 wget和普通下载有区别

    今天下的禅道 wget和用win下载之后再ssh传过去,效果不一样 wget不能正常启动禅道.回来要探讨一下wget的不同之处,先记下来

  3. Entity Framewor 学习笔记 (include + where)

    如果我们想在子查询做过滤的话应该怎样写呢? IEnumerable<Product> products = db.products.Include(p => p.colors.Whe ...

  4. ural 1723 Sandro's Book

    http://acm.timus.ru/problem.aspx?space=1&num=1723 #include <cstdio> #include <cstring&g ...

  5. Altium Designer中各层的含义

    1 Signal layer(信号层) 信号层主要用于布置电路板上的导线.Protel 99 SE提供了32个信号层,包括Top layer(顶层),Bottom layer(底层)和30个MidLa ...

  6. win10 pro eclipse maven: Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:mav invalid END header (bad central directory offset)

    Error:Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:mav ... invalid E ...

  7. C# 文件上传

     一.分析 本次博客,主要解决文件上传等一系列问题,将从两方面来论述,即1G以内文件和1G以上文件. 对于上传1G以内的文件,可以采用基本的三种上传方法:用Web控件FileUpload.html控件 ...

  8. js-权威指南学习笔记4

    第五章 语句 1.在JS中没有块级作用域,在语句块中声明的变量并不是语句块私有的. 2.尽管函数声明语句和函数定义表达式具有相同的函数名,但二者仍然不同.两种方式都创建了新的函数对象,但函数声明语句中 ...

  9. ibatis的selectkey

    在使用ibatis插入数据进数据库的时候,会用到一些sequence的数据,有些情况下,在插入完成之后还需要将sequence的值返回,然后才能进行下一步的操作.       使用ibatis的sel ...

  10. Append加载动态轮播

    前几天遇到了些小麻烦,不过很快就解决了.之所以要记下来是因为作为一名前端的程序员,要理解页面的加载顺序是最重要的.要不然自己写程序意外的出现bug~~ 刚开始写利用Append的时候,利用火狐的fir ...