简体   繁体   English

淡入灯箱,然后单击背景使其消失

[英]Fade lightbox in, and click on background and make it disappear

Hi! 嗨! I'm trying to make a lightbox, and I've got everything to work. 我正在尝试制作一个灯箱,并且一切正常。 You can click here to see it in live mode . 您可以单击此处以实时模式查看它 What I want to do now, is to be able to click on the background and then the box will disappear. 我现在想做的是能够单击背景,然后该框消失。 Also, when you click "Åpne Lysbildefremvisningen" the lightbox and background will fade nicely in, and when you click "close" og click on the background it will fade back out. 另外,当您单击“ÅpneLysbildefremvisningen”时,灯箱和背景会很好地淡入,当您单击“关闭”或单击背景时,它会淡出。 I couldn't understand how to do that. 我不明白该怎么做。 Thank you! 谢谢!

Index.html Index.html

<h1><a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Start lysbildevisningen</a></h1>

Style.css Style.css

.black_overlay {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.1;
opacity:.10;
filter: alpha(opacity=10);
}
.white_content {
    display: none;
    position: absolute;
    top: 30%;
    left: 30%;
    width: 640px;
    padding: 10px;
    background-color: #FFF;
    z-index:1002;
    overflow: auto;
    -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
}

You should listen to the click event of the div with the black_overlay class. 您应该使用black_overlay类来监听div的click事件。 And within it, change the style.display of the main div. 在其中更改主div的style.display。

Have you ever used a client framework as jQuery ow extJS? 您是否曾经将客户端框架用作jQuery ow extJS? They ease a lot this kind of work, and some plugins based on those framworks do all the work for you. 它们简化了此类工作,并且某些基于这些framworks的插件可以为您完成所有工作。 Write all the code from scratch is a good option only when you are really interested in learn the javaScript foundamentals. 仅当您真正有兴趣学习javaScript基础知识时,才从头开始编写所有代码是一个不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM