javascript - 当脚本试图使固定元素可见时,我的 JavaScript 代码在 Chrome 中崩溃

标签 javascript html css google-chrome

我添加了一些带有“visibility:hidden; position:fixed;”的元素到页面顶部,出于某种原因,当我在 Chrome 中启动脚本时,它使“#pageOverlay”可见,但无法取消隐藏其他元素。这是失败的 JS 函数:

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;
}

在 Firefox 和 IE11 中不会发生同样的事情,如果我更改所有“position:fixed;”,它只在 chrome 中有效。到“position:absolute;”;这不是我想要使用的。

使用脚本的页面在这里:

http://spongebobia.com/spongebob-captures/gallery.php

实际的脚本在这里:

http://spongebobia.com/spongebob-captures/scripts/previewArea.js

如何在保持“位置:固定;”的同时使其工作?

最佳答案

关于"z-index" .您的 pageOverlay 的 CSS 应如下所示:

#pageOverlay {
    background: gray;
    width: 100%;
    height: 100%;
    z-index: 500;
    top: 0px;
    left: 0px;
    position: fixed;
    visibility: hidden;
    z-index: 2;
}

你的 previewAreaContainer 是这样的:

#previewAreaContainer {
    position: fixed;
    visibility: hidden;
    top: 10px;
    left: 50%;
    margin-left: -344px;
    width: 670px;
    height: 540px;
    z-index: 3;
}

关于javascript - 当脚本试图使固定元素可见时,我的 JavaScript 代码在 Chrome 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32037264/

相关文章:

html - CSS Fixed - 将 HTML 元素保持在适当位置的替代方法

javascript - 如何在安卓浏览器中制作滚动条

javascript - 结合矩阵中的多次旋转

javascript - 如何在 Angular 中获取 clientHeight?

javascript - Angularjs 中的子字符串使用过滤器?

javascript - 为 var 创建数组

html - CSS - 如果 div 为空,则显示内容

javascript - 如何使用条件参数查询 mongodb 中的多个文档

html - 防止折叠的导航栏将内容推送到下方

html - 网络套件。将鼠标悬停在图像 'alt' 上不起作用