简单的LightBox Javascript弹出
Simple LightBox Javascript Popup
我想添加一个自动弹出灯箱到我的网站。
我需要能够将它添加到我的Html页面。我使用wordpress,但我的脚本只允许我插入html代码。我不能使用插件。
任何Java脚本都可以工作。我想发布一个图像,它说在页面上,直到人关闭它。但我也希望图像是可点击的
谢谢
function showPopup() {
document.getElementById('blackOverlay').style.display = 'block';
document.getElementById('popup').style.display = 'block';
}
function closePopup() {
document.getElementById('blackOverlay').style.display = 'none';
document.getElementById('popup').style.display = 'none';
}
.blackOverlay {
display:none;
background:rgba(0,0,0,.6);
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
z-index:1;
}
.popup {
display:none;
background:#fff;
position:fixed;
top:10%;
left:50%;
width:600px;
height:80%;
margin-left:-300px;
z-index:10;
border:2px solid #000;
}
.closePopup {
float:right;
font-weight:bold;
color:red;
cursor:pointer;
}
img {
max-width:100%;
max-height:100%;
}
<body onload="showPopup()">
<div>
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
</div>
<div id="blackOverlay" class="blackOverlay"></div>
<div id="popup" class="popup">
<span class="closePopup" onclick="closePopup()">X</span>
<img src="http://dummyimage.com/600x400/fff/000.png" />
</div>
</body>
您可以使用以下插件http://lokeshdhakar.com/projects/lightbox2/下载js并将其添加到您的header.php或footer.php文件
- http://www.jasonbutz.info/bootstrap-lightbox/
- http://getbootstrap.com/javascript/情态动词 下载所需的js,将其添加到模板文件中,并初始化js调用
如果你想要一些不使用任何插件的简单的东西,你将不得不使用至少一些JavaScript和CSS。
你可以有一个隐藏的div,你的位置固定在你的页面。当页面加载时,您可以显示它。在这个div中,你可以放置任何你想要的东西和一个元素来关闭它。
你可以看到下面一个简单的弹出。Javascript部分包含2个函数,打开和关闭弹出窗口。正如你所看到的,我在页面内容和弹出框之间添加了一个黑色的覆盖层。
第二部分是简单的CSS来定位你的弹出框在页面上的位置。
最后,你可以看到你的弹出窗口所需的HTML标记。
function showPopup() {
document.getElementById('blackOverlay').style.display = 'block';
document.getElementById('popup').style.display = 'block';
}
function closePopup() {
document.getElementById('blackOverlay').style.display = 'none';
document.getElementById('popup').style.display = 'none';
}
.blackOverlay {
display:none;
background:rgba(0,0,0,.6);
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
z-index:1;
}
.popup {
display:none;
background:#fff;
position:fixed;
top:10%;
left:50%;
width:600px;
height:80%;
margin-left:-300px;
z-index:10;
border:2px solid #000;
}
.closePopup {
float:right;
font-weight:bold;
color:red;
cursor:pointer;
}
img {
max-width:100%;
max-height:100%;
}
<body onload="showPopup()">
<div>
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
Content behind!Content behind!Content behind!Content behind!Content behind!<br />
</div>
<div id="blackOverlay" class="blackOverlay"></div>
<div id="popup" class="popup">
<span class="closePopup" onclick="closePopup()">X</span>
<img src="http://dummyimage.com/600x400/fff/000.png" />
</div>
</body>
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- Javascript排序的图像弹出窗口..可以't单独弹出
- 自动关闭弹出窗口的Javascript
- 将JavaScript弹出菜单转换为警报框
- IE7和Javascript“;出现错误“;弹出窗口
- javascript弹出窗口没有正确加载html表单
- 如果弹出窗口关闭,Javascript停止/重置计时器
- 如何在Ol3弹出窗口中添加用javascript创建的按钮上的点击事件
- 试图修改此javascript代码以减小弹出窗口的大小,或者在用户单击框外时关闭
- 关闭弹出窗口并刷新父页面javascript
- 为我的rails应用程序显示javascript弹出消息
- 在元素悬停上显示带有javascript的弹出式网站
- Javascript:为页面上的所有图像制作模式弹出窗口
- 从子窗口到父窗口的Javascript弹出选择器
- JavaScript sweetAlert弹出窗口在一秒钟后自动关闭
- 点击时弹出 Javascript 不起作用
- 如何防止弹出javascript onclick事件
- 弹出Javascript菜单
- JavaFXWebView-弹出Javascript上下文菜单
- 如何覆盖或弹出javascript try/catch块