JS 弹出层 这个比较实用

 

弹出层测试

名称:
密码:
 


一个简单的JS弹出层

基本功能

//主函数 id:内容,strTitle:标题,fn_msgBoxBack:关闭时回调函数,notShowClose:是否隐藏关闭按钮
function msgBox(id, strTitle, fn_msgBoxBack, hideClose)

//主函数 id:内容ID,strTitle:标题,fn_msgBoxBack:关闭时回调函数,notShowClose:是否隐藏关闭按钮

msgBox(id, strTitle, fn_msgBoxBack, hideClose)

msgBox_close() 关闭对话框

msgBox_alert(strAlert, strTitle) 提示框

msgBox_loading(strAlert, strTitle) 加载中

快捷键ESC关闭对话框

兼容 IE、FireFox、Chrome

主要遇到的问题

取父节点应当使用 div.parentNode;

取鼠标位置

 

?
1
2
3
4
5
6
onmousedown= "msgBox_moveStart(event);"
function msgBox_moveStart(evt){
  evt = evt ? evt : (window.event ? window.event : null );
  msgBox_mouseX = evt.clientX;
  msgBox_mouseY = evt.clientY;
}

 

style.left、style.top、style.width、style.height 附值时,应当加上 px

div.style.left = left + 'px';

添加事件

 

?
1
2
3
4
5
if (isIE){
  document.attachEvent( 'onmousemove' , msgBox_move);
} else {
  document.addEventListener( 'mousemove' , msgBox_move, false );
}

 

获取页面总宽度(包含非可见区域)document.documentElement.scrollWidth

透明度

 

?
1
2
3
4
5
6
7
if (isIE){
  div.style.filter = 'Alpha(opacity=20)' ;
} else if (navigator.userAgent.indexOf( "Chrome" ) > -1) //判断是否Chrome{
  div.style.opacity = 0.2;
} else {
  div.style.MozOpacity = 0.2;
}

 

实例及源码 下载

 

转载地址:http://www.cnblogs.com/zjfree/archive/2010/04/27/1722041.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值