html怎么自动弹出模态框,html模态弹出窗口

以下是一个简单的JavaScript示例:

Basic modal demo

body { margin: 0; }

#shade,#modal { display: none; }

#shade { position: fixed; z-index: 100; top: 0; left: 0; width: 100%; height: 100%; }

#modal { position: fixed; z-index: 101; top: 33%; left: 25%; width: 50%; }

#shade { background: silver; opacity: 0.5; filter: alpha(opacity=50); }

Start

var modal= document.getElementById('modal');

var shade= document.getElementById('shade');

document.getElementById('start').οnclick= function() {

modal.style.display=shade.style.display= 'block';

};

document.getElementById('close').οnclick= function() {

modal.style.display=shade.style.display= 'none';

};

// This code is a workaround for IE6's lack of support for the

// position: fixed style.

//

if (!('maxHeight' in document.body.style)) {

function modalsize() {

var top= document.documentElement.scrollTop;

var winsize= document.documentElement.offsetHeight;

var docsize= document.documentElement.scrollHeight;

shade.style.height= Math.max(winsize,docsize)+'px';

modal.style.top= top+Math.floor(winsize/3)+'px';

};

modal.style.position=shade.style.position= 'absolute';

window.οnscrοll=window.οnresize= modalsize;

modalsize();

}

您可以从中进行各种改进,例如iframe可以修复IE z-indexing,或将其封装在可重用的对象中,但这是完成的基本方法.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值