灯箱无法正常工作

时间:2015-08-14 05:57:22

标签: javascript jquery css

我需要点击一个链接来显示一个灯箱。问题是,一旦灯箱出现,我应该点击灯箱按钮或更改屏幕尺寸以查看图像。一旦链接被点击,似乎图像不会被加载。

Demo

<!DOCTYPE html>
<html lang="en">
<head>
  <title>slick - the last carousel you'll ever need</title>
  <link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/slick/slick.css"/>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/slick/slick-theme.css"/>
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/css/style.css">
  <link rel="stylesheet" type="text/css" href="http://kenwheeler.github.io/slick/css/prism.css" />

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
  <script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js" type="text/javascript"></script>
  <style>
#pageOverLay {
  background: #fff none repeat scroll 0 0;
  margin-left: 43%;
  margin-top: 10%;
  position: absolute;
  width: 500px;
  z-index: 1001;
  display:none;
}
#pageOverLay-shadow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    filter: alpha(opacity=75);
    -moz-opacity: 0.75;
    -khtml-opacity: 0.75;
    opacity: 0.75;
    z-index: 1000;
    display: none;
}
#pageOverLayCloseBtn{
    position:absolute;
    top:0;
    right:0;
}
.slick-slider {
    margin: 30px auto 50px;
}
.slick-slider {
    -moz-user-select: none;
    box-sizing: border-box;
    display: block;
    position: relative;
}
</style>
</head>
<body>
 <a onclick="showLightBox();" href="#">Click Here to show lightbox</a>
        <div id="pageOverLay-shadow"></div>
        <div id="pageOverLay">
       <div id="pageOverLayCloseBtn"><a href="#" onclick="pageOverLayClose();">X</a></div>
        <h2>Images</h2>
        <div class="slider fade">
          <div><div class="image"><img src="http://wowslider.com/sliders/demo-94/data1/images/photo1427806208781b36531cb09ef.jpg"/></div></div>
          <div><div class="image"><img src="http://wowslider.com/sliders/demo-94/data1/images/photo142855067022515f007f6f1ba.jpg"/></div></div>
          <div><div class="image"><img src="http://wowslider.com/sliders/demo-94/data1/images/photo1428452788387375d846a8ab4.jpg"/></div></div>
        </div>
        </div>




    <script src="view-source:http://kenwheeler.github.io/slick/code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="view-source:http://kenwheeler.github.io/slick/code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script type="text/javascript" src="http://kenwheeler.github.io/slick/slick/slick.js"></script>
    <script type="text/javascript" src="http://kenwheeler.github.io/slick/js/scripts.js"></script>
    <script type="text/javascript" src="http://kenwheeler.github.io/slick/js/prism.js"></script>
    <script type="text/javascript">

    function showLightBox(){
            $("#pageOverLay-shadow").css("display","block");
            $("#pageOverLay").css("display","block");

        }

        function pageOverLayClose(){
            $("#pageOverLay-shadow").css("display","none");
            $("#pageOverLay").css("display","none");
        }
        var disqus_shortname = 'slickcarousel';

        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>

</body>
</html>

1 个答案:

答案 0 :(得分:1)

css-attribute display:none;在div上,浏览器阻止渲染甚至加载该元素内的图像。 有一个很好的解释:Does “display:none” prevent an image from loading?

只需交换&#34;显示:无;&#34; &#34;可见性:隐藏;&#34;并更新您的JavaScript - &gt;见下文。

<强> CSS:

#pageOverLay {
    background: #fff none repeat scroll 0 0;
    margin-left: 43%;
    margin-top: 10%;
    position: absolute;
    width: 500px;
    z-index: 1001;
    visibility:hidden;
}
#pageOverLay-shadow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    filter: alpha(opacity=75);
    -moz-opacity: 0.75;
    -khtml-opacity: 0.75;
    opacity: 0.75;
    z-index: 1000;
    visibility: hidden;
}

<强> JS / jQuery的:

...
function showLightBox() {
     $("#pageOverLay-shadow").css("visibility", "visible");
     $("#pageOverLay").css("visibility", "visible");
 }
...

我更新了jsfiddle:http://jsfiddle.net/dm3Lea95/4/ (还修复了&#34;关闭&#34;按钮;))