首页 > 解决方案 > 为什么它在 Safari 中有效,但在 Chrome 中无效?

问题描述

这个带有简单 CSS 和 JS 的 HTML 在 Safari 中完美运行,但在 Chrome(Mac 和 Win)中它根本不起作用,甚至不能滚动……不确定是 JS,还是 CSS,或两者兼而有之。我试图更改脚本或 CSS,但没有任何效果。

请帮忙

https://codepen.io/sinetempore/pen/oNwNKZr

这是我的 HTML 和我的 CSS:

document.querySelector('.parallax').addEventListener('scroll', function() {
  if ($(this).scrollTop() > 100) {
    $('.p1, .p2').addClass('hide');
  } else {
    $('.p1, .p2').removeClass('hide');
  }
});

document.querySelector('.parallax').addEventListener('scroll', function() {
  if ($(this).scrollTop() > 1200) {
    $('.p3').addClass('hide');
    $('.p2').removeClass('hide');
  } else {
    $('.p3').removeClass('hide');
  }
});

document.querySelector('.parallax').addEventListener('scroll', function() {
  if ($(this).scrollTop() > 1800) {
    $('.p3-text, .p3sottocntr, .p-main.p4-text').addClass('hidefoot');
  } else {
    $('.p3-text, .p3sottocntr, .p-main.p4-text').removeClass('hidefoot');
  }
});

/// Scroll back to top
$("a[href='.parallax']").click(function() {
  $("html, body").animate({
    scrollTop: 0
  }, "slow");
  return false;
});
@charset "utf-8";
* {
  margin: 0;
}

body {
  height: 100vh;
  overflow-x: hidden;
  overflow-y: hidden;
  font-family: MuseoSans_700;
}

a {
  color: black;
  text-decoration: none;
}


/* ---------- LOGO ----------*/

.logo-p1 {
  overflow: hidden;
  border: 0px solid red;
  width: 120px;
  height: 45px;
  background-color: white;
  position: absolute;
  top: calc(50% - 22.5px);
  left: calc(50% - 60px);
  margin: 0;
}

.logo-p2 {
  left: 0;
  overflow: hidden;
  border: 0px solid red;
  width: 100px;
  height: 100px;
  background-color: white;
  position: absolute;
  top: 40px;
  left: 40px;
  margin: 0;
}

.logo-p3 {
  transform: rotate(180deg);
  left: 0;
  overflow: hidden;
  border: 0px solid red;
  width: 100px;
  height: 100px;
  background-color: white;
  position: absolute;
  top: 40px;
  left: 40px;
  margin: 0;
}


/* ---------- PARALLAX ----------*/

.parallax {
  perspective: 1px;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: static;
  background: rgba(255, 0, 0, 0);
  z-index: 2;
}

.speed-1 {
  transform: translateZ(-6px) scale(7);
}


/* ---------- SECTIONS ----------*/

.p1 {
  height: 100%;
  width: 100%;
  position: absolute;
  display: block;
  z-index: 3;
  background: white;
  opacity: 1;
  transition: all 0.9s ease;
}

.p1.hide {
  opacity: 0;
  transition: all 0.9s ease;
  visibility: hidden;
}

.p2 {
  height: auto;
  width: 100%;
  position: fixed;
  display: block;
  z-index: 2;
  top: 0vh;
  background: white;
  visibility: hidden;
  transition: all 0.4s ease;
  opacity: 0;
}

.p2.hide {
  opacity: 1;
  transition: all 0.9s ease;
  visibility: visible;
}

.p3 {
  height: auto;
  width: 100%;
  position: fixed;
  display: block;
  z-index: 2;
  top: 0vh;
  background: white;
  visibility: hidden;
  transition: all 0.4s ease;
  opacity: 0;
}

.p3.hide {
  opacity: 1;
  transition: all 0.9s ease;
  visibility: visible;
}

.p-main.p4-text.hidefoot {
  width: 100%;
  height: 250px;
  background-color: black;
  /* position: relative; */
  left: 0px;
  margin: auto;
  bottom: 250px;
}

.p-main.p4-text {
  width: 100%;
  height: 0px;
  background-color: black;
  position: fixed;
  left: 0px;
  margin: auto;
  bottom: 0px;
  clip-path: polygon(0 40%, 100% 0, 100% 100%, 0% 100%);
  -webkit-clip-path: polygon(0 40%, 100% 0, 100% 100%, 0% 100%);
  transition: all 0.9s;
  transform: translateY(250px);
  transform-origin: bottom;
}

.p4 {
  height: auto;
  width: 100%;
  position: relative;
  display: block;
  z-index: -1;
}

.p4.hidefoot {
  opacity: 1;
  transition: all 0.9s ease;
  visibility: visible;
}


/* ---------- TESTO SECTIONS ----------*/

.p-main {
  width: 355px;
  height: 230px;
  background-color: transparent;
  position: fixed;
  bottom: 40px;
  left: 40px;
  margin: 0;
  display: flex;
  justify-content: left;
  align-items: flex-end;
  border: 0px solid red;
  filter: invert(0);
  font-family: MuseoSans-100;
  font-size: 13px;
  font-smoothing: antialiased;
}

.p3-text {
  opacity: 1;
  transition: all 0.9s ease;
  visibility: visible;
}

.p3-text.hidefoot {
  opacity: 0;
  transition: all 0.9s ease;
  visibility: hidden;
}

.p-desc {
  line-height: 16px;
}

.p-desc b {
  font-family: MuseoSans_700;
  font-weight: normal;
}

.p-col {
  margin-top: 20px;
  column-count: 2;
  line-height: 16px;
  font-family: MuseoSans_700;
}


/* ---------- MENU SOTTO ----------*/

.sottocentro {
  width: 250px;
  height: 140px;
  background-color: transparent;
  position: fixed;
  bottom: 40px;
  right: calc(0% - 0px);
  margin: 0;
  display: -webkit-box;
  justify-content: center;
  align-items: flex-end;
  filter: invert(0);
  font-family: MuseoSans-100;
  font-size: 13px;
  font-smoothing: antialiased;
  border: 0px solid red;
  right: 40px;
}

.p3sottocntr {
  opacity: 1;
  transition: all 0.9s ease;
  visibility: visible;
}

.p3sottocntr.hidefoot {
  opacity: 0;
  transition: all 0.9s ease;
  visibility: hidden;
}

.sottocentro ul {
  list-style: none;
  text-align: right;
  width: auto;
  border: 0px solid red;
  line-height: 16px;
  text-decoration: none;
  clear: both;
  margin: 0;
  padding: 0px;
  right: 40px;
  position: absolute;
  right: 0px;
  position: absolute;
  bottom: 0px;
}

.sottocentro ul li {
  border: none;
  text-align: right;
  width: auto;
}

.sottocentro ul li.begins {
  border: none;
  text-align: right;
  width: auto;
  padding: 30px 0 0 0;
}
<!DOCTYPE html>

<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" media="all" href="css/style.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
  <div class="parallax">
    <section class="p1 speed-1">
      <div class="logo-p1">
        <img src="https://www.google.com/logos/doodles/2021/doodle-champion-island-games-august-24-6753651837108999-s.png"></img>
      </div>
    </section>
  </div>
  <section class="p2">
    <div class="logo-p2">
      <img src="https://www.google.com/logos/doodles/2021/doodle-champion-island-games-august-24-6753651837108999-s.png"></img>
    </div>
    <div class="p-main p2-text">
      <div>
        <p class="p-desc p2-desc"> <b>Lorem ipsum </b>dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
          aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum..
        </p>
      </div>
    </div>
  </section>
  <section class="p3">
    <div class="logo-p3">
      <img src="https://www.google.com/logos/doodles/2021/doodle-champion-island-games-august-24-6753651837108999-s.png"></img>
    </div>
    <div class="p-main p3-text">
      <div>
        <p class="p-desc p3-desc"> <b>Sed ut perspiciatis </b>unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem
          quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam
          eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit
          qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
        </p>
      </div>
    </div>
  </section>
  <section class="p4">
    <div class="p-main p4-text">

    </div>
  </section>
</body>

</html>

标签: javascripthtmlcssgoogle-chrome

解决方案


推荐阅读