灯箱在任何过渡时淡入淡出

时间:2012-02-11 20:44:15

标签: javascript css3 lightbox transition

我正在尝试使用基于css和一些javascript的灯箱淡入淡出。到目前为止,我只是设法褪色。我怎么能让它淡出?

的style.css:

@-webkit-keyframes FadeIn {
0% {
    opacity:0;
}
10% {
    opacity:0.1;
}
}
.overlay {
    position: absolute;
    top: 0%;
    left: 0%;
    width: 100%;
    height: 100%;
    -moz-opacity: 0.1;
    opacity:.10;
    background: #000;
    filter: alpha(opacity=10);
    z-index:1001;
    -webkit-animation-name: FadeIn;
    webkit-animation-timing-function: ease-in-out;
    -webkit-animation-duration: 8s;
}
.lightbox {
    background: #FFF;
    width: 640px;
    padding: 20px;
    position: absolute;
    left: 30%;
    top: 20%;
    font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Arial, sans-serif;
    font-size: 13px;
    color: #786c6d;
    -webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
    -moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.5);
    z-index:1002;
    -webkit-animation-name: FadeIn;
    -webkit-animation-timing-function: ease-in-out;
    -webkit-animation-duration: 1s;
}

HTML

<a href="javascript:void(0)" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'">Start lysbildevisningen</a>
    <div id="light" class="lightbox">
        <img src="http://farm8.staticflickr.com/7169/6765756923_bb4252c86f_z.jpg" alt="" width="640" height="426" />
    <br>
    <a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a></div>
            <div id="fade" class="overlay"></div> 

1 个答案:

答案 0 :(得分:0)

您可以使用jQuery并使用动画fadeIn() show() slideDown()等。

HTML:

<a href="#" onclick="overlay();">Start ;)</div>
<div id="overlay" onclick="disoverlay();"></div>
<div id="lightbox">
    <img src="http://farm8.staticflickr.com/7169/6765756923_bb4252c86f_z.jpg" alt="" width="640" height="426" /><br />
    <a href="#" onclick="disoverlay();">Close lysbildevisningen</a>
</div>

JavaScript(使用以前的jQuery插入):

function overlay(){
    $("#overlay").fadeIn("slow");
    $("#lightbox").fadeIn("slow");
}
function disoverlay(){
    $("#overlay").fadeOut("slow");
    $("#lightbox").fadeIn("slow");
}

CSS:

.overlay{
position: absolute;
display:none;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
opacity: 0.1;
}