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

 更新时间:2016年09月29日 09:40:55   投稿:jingxian  
下面小编就为大家带来一篇JS当前页面登录注册框,固定DIV,底层阴影的实例代码。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

这是一个实例,保存代码为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,底层阴影的实例代码的全部内容了,希望对大家有所帮助,多多支持脚本之家~

相关文章

  • 解决AJAX中跨域访问出现''没有权限''的错误

    解决AJAX中跨域访问出现''没有权限''的错误

    很多人在使用AJAX调用别人站点内容的时候,JS会提示"没有权限"错误,这是XMLHTTP组件的限制-安全起见
    2008-08-08
  • yii form 表单提交之前JS在提交按钮的验证方法

    yii form 表单提交之前JS在提交按钮的验证方法

    很多时候,需要对Yii表单model中的对象设置的rules进行判断,但是有的时候可能需要在提交之前就在客户端进行验证。怎么处理呢?接下来通过本文给大家分享yii form 表单提交之前JS在提交按钮的验证方法,需要的的朋友参考下
    2017-03-03
  • javascript自定义函数参数传递为字符串格式

    javascript自定义函数参数传递为字符串格式

    本节主要介绍了通过自定义javascript函数传递参数为字符串格式的,用this传递、引号缺省,示例如下
    2014-07-07
  • TypeScript中的类

    TypeScript中的类

    这篇文章主要介绍了TypeScript中的类,类这个概念基本是所有面向对象编程语言都具有一个概念,JavaScript中ES6 之前是没有类这个概念,下面文章围绕TypeScript类的相关资料展开内容,需要的朋友可以参考一下
    2021-12-12
  • javascript函数特点实例分析

    javascript函数特点实例分析

    这篇文章主要介绍了javascript函数特点,实例分析了javascript函数传递参数及调用方法,需要的朋友可以参考下
    2015-05-05
  • Bootstrap响应式侧边栏改进版

    Bootstrap响应式侧边栏改进版

    这篇文章主要为大家详细介绍了Bootstrap响应式侧边栏改进版,结合导航条和下拉菜单进行改进,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-09-09
  • jquery实用技巧之输入框提示语句

    jquery实用技巧之输入框提示语句

    输入有效信息时会有一些提示语,比如“请输入用户名”和“请输入密码”等语言,这篇文章就为大家介绍js实用技巧之输入框提示语句的实现方法,感兴趣的小伙伴们可以参考一下
    2016-07-07
  • JavaScript之HTMLCollection接口代码

    JavaScript之HTMLCollection接口代码

    JavaScript之HTMLCollection接口代码,需要的朋友可以参考下。
    2011-04-04
  • 详谈ES6中的迭代器(Iterator)和生成器(Generator)

    详谈ES6中的迭代器(Iterator)和生成器(Generator)

    下面小编就为大家带来一篇详谈ES6中的迭代器(Iterator)和生成器(Generator)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-07-07
  • three.js加载obj模型的实例代码

    three.js加载obj模型的实例代码

    three.js是一款webGL框架,由于其易用性被广泛应用。接下来通过本文给大家分享three.js加载obj模型的实例代码,需要的朋友参考下吧
    2017-11-11

最新评论