当脚本试图使固定元素可见时,我的JavaScript代码在Chrome中崩溃
我在页面顶部添加了几个“可见性:隐藏;位置:固定;”的元素,出于某种原因,当我在Chrome中启动脚本时,它会使“#pageOverlay”可见,但无法取消隐藏其他元素。以下是失败的JS函数:当脚本试图使固定元素可见时,我的JavaScript代码在Chrome中崩溃,javascript,html,css,google-chrome,Javascript,Html,Css,Google Chrome,我在页面顶部添加了几个“可见性:隐藏;位置:固定;”的元素,出于某种原因,当我在Chrome中启动脚本时,它会使“#pageOverlay”可见,但无法取消隐藏其他元素。以下是失败的JS函数: function showImage(element) { //locating currentGalleryItemIndex for (currentGalleryItemIndex = firstGalleryItemIndex; currentGalleryItemIndex <= las
function showImage(element) {
//locating currentGalleryItemIndex
for (currentGalleryItemIndex = firstGalleryItemIndex; currentGalleryItemIndex <= lastGalleryItemIndex; currentGalleryItemIndex++) {
if (galleryItems[currentGalleryItemIndex] === element) break;
}
//general settings
fillPreviewArea();
pageOverlay.style.visibility = "visible";
previewArea.style.visibility = "visible";
previewAreaCloseLink.style.visibility = "visible";
previewAreaActive = true;
}
函数showImage(元素){
//查找currentGalleryItemIndex
对于(currentGalleryItemIndex=firstGalleryItemIndex;currentGalleryItemIndex它是关于。您的页面覆盖的CSS应该如下所示:
#pageOverlay {
background: gray;
width: 100%;
height: 100%;
z-index: 500;
top: 0px;
left: 0px;
position: fixed;
visibility: hidden;
z-index: 2;
}
#previewAreaContainer {
position: fixed;
visibility: hidden;
top: 10px;
left: 50%;
margin-left: -344px;
width: 670px;
height: 540px;
z-index: 3;
}
您的预览容器如下所示:
#pageOverlay {
background: gray;
width: 100%;
height: 100%;
z-index: 500;
top: 0px;
left: 0px;
position: fixed;
visibility: hidden;
z-index: 2;
}
#previewAreaContainer {
position: fixed;
visibility: hidden;
top: 10px;
left: 50%;
margin-left: -344px;
width: 670px;
height: 540px;
z-index: 3;
}
谢谢!我必须重新配置z索引才能正常工作。