javascript - 使用 Javascript 操作时 z-index 在 Safari 上不起作用

标签 javascript css web safari z-index

我正在制作一个具有多层的网站,它通过事件 react (如 onclick)在 Javascript 中操纵 z-index 来回移动。我有一个导航栏,与其他所有元素相比,它的 z-index 值都很大,因为我希望它无论如何都位于最前面。 但是,当在 Safari 上运行时,导航栏会从一开始就消失,但它在 Google Chrome 和 FireFox 上运行良好。 我已经包含了指定此 Angular 色的 css 代码和 javascript 代码:

JavaScript:

 //Global variables representing DOM elements
var introTitleElem = document.getElementById('introduction-title');
var resumeElem = document.getElementById('resume-container');
var introElem = document.getElementById('intro-content');
var eduElem = document.getElementById('edu-content');

//Layer tracker (for transition effect)
var prev = introElem;
var prevButton = "";

//Function that actually changes the layers
function changeLayer(layer, button) {
    if (layer === prev) return;
    introTitleElem.style.opacity = "0";
    prev.style.zIndex = "40";
    layer.style.zIndex = "50";
    layer.style.cssText = "opacity: 1; transition: opacity 0.5s";
    prev.style.zIndex = "5";
    prev.style.opacity = "0";
    prev = layer;
    if (prevButton !== "") prevButton.style.textDecoration = "none";
    button.style.textDecoration = "underline";
    prevButton = button;
}

//Manages events triggered by name button toggle
function revealResume() {
    introTitleElem.style.zIndex = "0";
    resumeElem.style.zIndex = "10";
    resumeElem.style.opacity = "1";
    introElem.style.opacity = "1";
    resumeElem.style.transition = "opacity 0.7s";
    introElem.style.transition = "opacity 0.7s";
}
document.getElementById("name-title").addEventListener("click", revealResume);

 //Manage z-index of different components of the resume and reveal them accordingly
$('#nav-education').click(function () {
    onEducation = true;
    changeLayer(eduElem, this);
});

CSS(SASS):

/*NAVIGATION STYLING*/
#fixed-nav {
  align-self: flex-start;
  overflow-x: hidden;
  float: right;
  z-index: 9999 !important;
  display: flex;
  margin: 1em;

  li {
    margin: 0.6em;
    font: {
      family: $font-plex-sans-condensed;
      size: 0.8em;
    }
    text-align: center;
    color: $lightest-grey;
    transition: color 0.3s;
    &:hover {
      cursor: pointer;
      color: $dark-grey;
      transition: color 0.3s;
    }
  }
}

/*OVERALL DIV FORMATTING*/
.format-div {
  width: 100vw;
  height: 100vh;
  display: flex;
  position: absolute;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  opacity: 0;
}

/*EDUCATION CONTENT STYLING*/
#edu-content {
  background-color: $red-1;
}

HTML:

<div id="resume-container">
<ul id="fixed-nav">
    <li id="nav-education">education.</li>
    <li id="nav-experiences">experiences.</li>
    <li id="nav-skills">skills.</li>
    <li id="nav-projects">projects.</li>
    <li id="nav-additional">additional.</li>
    <li id="nav-contact">contact.</li>
</ul>
<div id="intro-content" class="format-div">
    <h1 class="type-effect">
        &lt;h1&gt;I'm Daniel <b>(Sang Don)</b> Joo&lt;/h1&gt;
        <span class="blinking-cursor">|</span>
    </h1>
</div>
<div id="edu-content" class="format-div">
    <h1>education</h1>
</div>

很抱歉代码量太大,但我真的不确定这个问题的根源在哪里。干杯!

最佳答案

必须是元素的位置特征才能起作用

错误的例子(不工作)

.className { z-index: 99999 !important; }

正确的例子(有效)

.className { 位置:'相对'; z-index: 99999 !important; } .className { 位置:'绝对'; z-index: 99999 !important; } ETC..

祝你好运:)

关于javascript - 使用 Javascript 操作时 z-index 在 Safari 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51853181/

相关文章:

Javascript 将值传递给打开的窗口

javascript - 找不到 "<%"的匹配关闭标记

javascript - 自然排序数组数组

html - 基于 ul 的导航中的对齐和可点击区域

javascript - 如何使用 jquery 禁用或隐藏轮播下一个/上一个图标

javascript - 什么是随机替换百度统计(Analytics)的Javascript代码来对浏览器上的网站进行DDOS攻击?

javascript - 原型(prototype)自定义事件不在 DOM 元素上

html - 如何让 flex box 在 safari 中工作?

java - Java 中的点对点实时流媒体?

c++ - 如何在控制台应用程序中显示网站的源代码?