gpt4 book ai didi

javascript - 灯箱无法正常工作

转载 作者:行者123 更新时间:2023-11-28 16:56:39 25 4
gpt4 key购买 nike

我需要通过点击一个链接来显示一个灯箱。问题是一旦显示灯箱,我应该单击灯箱按钮或更改屏幕大小以查看图像。单击链接后似乎不会加载图像。

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>

最佳答案

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

只需交换“display: none;”具有“可见性:隐藏;”并更新您的 JavaScript -> 见下文。

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/(还修复了“关闭”按钮;))

关于javascript - 灯箱无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32003200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com