js当前页面登录注册框,固定div,底层阴影的实例代码


Posted in Javascript onOctober 04, 2016

这是一个实例,保存代码为html文件运行试试吧。兼容火狐、ie6、ie7、ie8、Chrome等。

<!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=gb2312" />
<title>JS当前页面登录注册框,固定DIV,底层阴影 - 三水点靠木</title>
<!--
一个按钮
点击之后 显示一个div
div要水平 垂直居中
当我浏览器高度 宽度变化的时候
div依然水平 垂直居中
点击遮罩层,浮动层隐藏
知识点:
1.如何用css控制div水平垂直居中
2.如何用js取得浏览器高度宽度
3.如何控制resize事件-->
<style type="text/css">
.hidden{ display:none}
/*评论浮动层*/
#smallLay{width:498px; height:100px;padding:4px 10px 10px;background-color:#FFFFFF;border:1px solid #05549d;color:#333333;line-height:24px;text-align:left;-webkit-box-shadow:5px 2px 6px #000;-moz-box-shadow:3px 3px 6px #555;}
</style>
</head>
<script type="text/javascript">
  //判断浏览器ie6创建的div的样式和非ie6创建的div的样式
  //创建div
  function showid(idname) {
    var isIE = (document.all) ? true : false;
    var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
    var newbox = document.getElementById(idname);
    newbox.style.zIndex = "9999";
    newbox.style.display = "block"
    newbox.style.position = !isIE6 ? "fixed" : "absolute";
    newbox.style.top = newbox.style.left = "50%";
    newbox.style.marginTop = -newbox.offsetHeight / 2 + "px";
    newbox.style.marginLeft = -newbox.offsetWidth / 2 + "px";
    var jihualayer = document.createElement("div");
    jihualayer.id = "jihualayer";
    jihualayer.style.width = jihualayer.style.height = "100%";
    jihualayer.style.position = !isIE6 ? "fixed" : "absolute";
    jihualayer.style.top = jihualayer.style.left = 0;
    jihualayer.style.backgroundColor = "#000";
    jihualayer.style.zIndex = "9998";
    jihualayer.style.opacity = "0.6";
    document.body.appendChild(jihualayer);
    var sel = document.getElementsByTagName("select");
    for (var i = 0; i < sel.length; i++) {
      sel[i].style.visibility = "hidden";
    }
    function jihualayer_iestyle() {
      jihualayer.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth)
+ "px";
      jihualayer.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) +
"px";
    }
    function newbox_iestyle() {
      newbox.style.marginTop = document.documentElement.scrollTop - newbox.offsetHeight / 2 + "px";
      newbox.style.marginLeft = document.documentElement.scrollLeft - newbox.offsetWidth / 2 + "px";
    }
    if (isIE) { jihualayer.style.filter = "alpha(opacity=60)"; }
    if (isIE6) {
      jihualayer_iestyle()
      newbox_iestyle();
      window.attachEvent("onscroll", function () {
        newbox_iestyle();
      })
      window.attachEvent("onresize", jihualayer_iestyle)
    }
    jihualayer.onclick = function () {
      newbox.style.display = "none"; jihualayer.style.display = "none"; for (var i = 0; i < sel.length; i++) {
        sel[i].style.visibility = "visible";
      } 
    }
  }
</script>
<body>
<div style="width:200px; height:100px;"></div>
<input name="" type="button" id="showbtn" value="点击显示" onclick="showid('smallLay')" />
<!--收藏浮层开始-->
<div id="smallLay" style="display:none" >
这<a href="http://jihua.cnblogs.com" style="text-decoration:none; color:Gray;">是</a>悬浮层
</div>
<!--收藏浮层结束-->
<div id="a" style="height:1000px;">这<a href="http://jihua.cnblogs.com" style="text-decoration:none; color:Black;">是</a>普通层</div>
</body>
</html>

以上就是小编为大家带来的js当前页面登录注册框,固定div,底层阴影的实例代码全部内容了,希望大家多多支持三水点靠木~

Javascript 相关文章推荐
防止xss和sql注入:JS特殊字符过滤正则
Apr 18 Javascript
JS特殊函数(Function()构造函数、函数直接量)区别介绍
May 19 Javascript
使用jquery hover事件实现表格的隔行换色功能示例
Sep 03 Javascript
快速解决jQuery与其他库冲突的方法介绍
Jan 02 Javascript
JavaScript中的style.cssText使用教程
Nov 06 Javascript
jQuery实现简单的列表式导航菜单效果代码
Aug 31 Javascript
JavaScript中this详解
Sep 01 Javascript
实例代码讲解jquery easyui动态tab页
Nov 17 Javascript
JavaScript中Math对象的方法介绍
Jan 05 Javascript
webpack-dev-server自动更新页面方法
Feb 22 Javascript
详解基于webpack&amp;gettext的前端多语言方案
Jan 29 Javascript
Vue实现跑马灯样式文字横向滚动
Nov 23 Vue.js
总结Javascript中数组各种去重的方法
Oct 04 #Javascript
Javascript中arguments对象的详解与使用方法
Oct 04 #Javascript
js判断浏览器是否支持严格模式的方法
Oct 04 #Javascript
浅谈jquery高级方法描述与应用
Oct 04 #Javascript
vue.js中$watch的用法示例
Oct 04 #Javascript
Angularjs实现带查找筛选功能的select下拉框示例代码
Oct 04 #Javascript
用jquery快速解决IE输入框不能输入的问题
Oct 04 #Javascript
You might like
php结合表单实现一些简单功能的例子
2011/06/04 PHP
php cli换行示例
2014/04/22 PHP
js对数字的格式化使用说明
2011/01/12 Javascript
jQuery :nth-child前有无空格的区别分析
2011/07/11 Javascript
jQuery验证Checkbox是否选中的代码 推荐
2011/09/04 Javascript
Javascript处理DOM元素事件实现代码
2012/05/23 Javascript
一个背景云变换js特效 鼠标移动背景云变化
2012/12/28 Javascript
第十章之巨幕页头缩略图与警告框组件
2016/04/25 Javascript
使用jquery提交form表单并自定义action的实现代码
2016/05/25 Javascript
Bootstrap的Refresh Icon也spin起来
2016/07/13 Javascript
前端实现文件的断点续传(前端文件提交+后端PHP文件接收)
2016/11/04 Javascript
JS操作input标签属性checkbox全选的实现代码
2017/03/02 Javascript
Angular实现预加载延迟模块的示例
2017/10/12 Javascript
微信小程序实现的涂鸦功能示例【附源码下载】
2018/01/12 Javascript
Vue的路由动态重定向和导航守卫实例
2018/03/17 Javascript
快速解决vue动态绑定多个class的官方实例语法无效的问题
2018/09/05 Javascript
详解vue使用插槽分发内容slot的用法
2019/03/28 Javascript
JavaScript indexOf()原理及使用方法详解
2020/07/09 Javascript
在elementui中Notification组件添加点击事件实例
2020/11/11 Javascript
addEventListener()和removeEventListener()追加事件和删除追加事件
2020/12/04 Javascript
[05:16]《大圣!大圣》——DOTA2新英雄齐天大圣配音李世宏老师专访
2016/12/13 DOTA
Python 闭包的使用方法
2017/09/07 Python
一道python走迷宫算法题
2018/01/22 Python
python框架中flask知识点总结
2018/08/17 Python
selenium+PhantomJS爬取豆瓣读书
2019/08/26 Python
Python内建序列通用操作6种实现方法
2020/03/26 Python
Python如何根据时间序列数据作图
2020/05/12 Python
Python如何优雅删除字符列表空字符及None元素
2020/06/25 Python
碧欧泉美国官网:Biotherm美国
2016/08/31 全球购物
拉夫劳伦爱尔兰官方网站:Ralph Lauren爱尔兰
2020/04/10 全球购物
C#基础面试题
2016/10/17 面试题
工作评语大全
2014/04/26 职场文书
环保倡议书范文
2014/05/12 职场文书
大学英语专业求职信
2014/06/21 职场文书
2015小学五年级班主任工作总结
2015/05/21 职场文书
2016高考寄语或鼓励的话语
2015/12/04 职场文书