html中弹框背景变暗,jquery实现网页背景变暗的弹框效果

很多网页的登陆就是在页面上弹出一个登陆框,背景变暗,通过jquery可以实现这个效果:

727ad8fbe0232fcd1e7caa90ce390232.png

Javascript代码:

var GB_DONE = false;

var GB_HEIGHT = 400;

var GB_WIDTH = 400;

function GB_show(caption, url, height, width) {

$("GB_window").remove();

GB_HEIGHT = height || 400;

GB_WIDTH = width || 400;

if(!GB_DONE) {

$(document.body)

.append("

+ "Close window

");

$("#GB_window img").click(GB_hide);

$("#GB_overlay").click(GB_hide);

$(window).resize(GB_position);

GB_DONE = true;

}

$("#GB_frame").remove();

//下面的append方法里的内容为弹出框的内容,可以自行设定

$("#GB_window").append("

   名称:

常量名:

   URL: 

target:_self_blank_parent_top

  描述:

");

$("#GB_caption").html(caption);

$("#GB_overlay").show();

$("#cancer").click(GB_hide);

GB_position();

$("#GB_window").slideDown("slow");

}

function GB_hide() {

$("#GB_window").slideUp("slow");

$("#GB_overlay").hide();

}

function GB_position() {

var de = document.documentElement;

var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;

$("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",

left: ((w - GB_WIDTH)/2)+"px" });

$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");

}

alert("sdf");

}

把下面的代码保存为greybox.js文件:

var GB_DONE = false;

var GB_HEIGHT = 400;

var GB_WIDTH = 400;

function GB_show(caption, url, height, width) {

$("GB_window").remove();

GB_HEIGHT = height || 400;

GB_WIDTH = width || 400;

if(!GB_DONE) {

$(document.body)

.append("

+ "Close window

");

$("#GB_window img").click(GB_hide);

$("#GB_overlay").click(GB_hide);

$(window).resize(GB_position);

GB_DONE = true;

}

$("#GB_frame").remove();

$("#GB_window").append("

   名称:

常量名:

   URL: 

target:_self_blank_parent_top

  描述:

");

$("#GB_caption").html(caption);

$("#GB_overlay").show();

$("#cancer").click(GB_hide);

GB_position();

$("#GB_window").slideDown("slow");

}

function GB_hide() {

$("#GB_window").slideUp("slow");

$("#GB_overlay").hide();

}

function GB_position() {

var de = document.documentElement;

var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;

$("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",

left: ((w - GB_WIDTH)/2)+"px" });

$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");

}

function enter(){

alert("sdf");

}

CSS代码:

#GB_overlay {

background-image: url(../images/overlay.png);

position: absolute;

margin: auto;

top: 0;

left: 0;

z-index: 100;

width: 100%;

height: 100%;

}

* html #GB_overlay {

background-color: #000;

background-color: transparent;

background-image: url(../images/blank.gif);

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="../images/overlay.png", sizingMethod="scale");

}

#GB_window {

top: 100px;

left: 0px;

position: absolute;

background: #fff;

border: 5px solid #aaa;

overflow: auto;

width: 400px;

height: 400px;

z-index: 150;

}

#GB_frame {

border: 0;

overflow: auto;

width: 100%;

height: 378px;

font-size:13px;

}

#GB_caption {

font: 12px bold helvetica, verdana, sans-serif;

color: #fff;

background: #888;

padding: 2px 0 2px 5px;

margin: 0;

text-align: left;

}

#GB_window img {

position: absolute;

top: 2px;

right: 5px;

cursor: pointer;

cursor: hand;

}

在网页中合理运用以上代码。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值