微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

进度指示器颜色根据部分背景颜色变化 (fullpage.js)

如何解决进度指示器颜色根据部分背景颜色变化 (fullpage.js)

我有一个 fullpage.js 导入到我的代码一个进度条指示器 (div class="progress-section")。我的问题是,如何根据部分的背景颜色更改进度条指示器? (例如,当部分背景颜色为白色时,进度指示器为黑色,当部分 bg 为黑色时,指示器为白色。)我非常感谢你们 :)

添加了以下代码

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <Meta charset="utf-8">
  <title>Aaron</title>
  <link rel="stylesheet" href="css/styles.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.1.2/fullpage.min.css" integrity="sha512-4rPgyv5iG0PZw8E+oRdfN/Gq+yilzt9rQ8Yci2jJ15rAyBmF0HBE4wFjBkoB72cxBeg63uobaj1UcNt/scV93w==" crossorigin="anonymous"
    referrerpolicy="no-referrer" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"></script>

</head>

<body>

  <!-- Navigation -->
  <!-- <header>
      <h4 class="logo">LIGHT</h4>
    </a>
    <nav>
      <ul>
        <li><a href="#hero">HOME</a></li>
        <li><a href="#about">ABOUT</a></li>
        <li> <a href="#contact">CONTACT</a></li>
      </ul>
    </nav>
  </header> -->
  <div class="progress-section">
    <div class="progress-bar-wrap" data-bg="fuchsia">
      <div class="progress-bar" ></div>
    </div>

    <div class="progress-num"></div>

  </div>

<div>




  <div id="fullpage">



    <div class="section one">
      Section ONE
    </div>

    <div class="section two">
      Section TWO
    </div>

    <div class="section three">
      Section THREE
    </div>

    <div class="section four">
      Section FOUR
    </div>

  </div>

  </div>


  <!-- Main Container Ends -->

  <script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/3.1.2/fullpage.min.js" integrity="sha512-gSf3NCgs6wWEdztl1e6vUqtRP884ONnCNzCpomdoQ0xXsk06lrxJsR7jX5yM/qAGkPGsps+4bLV5IEjhOZX+gg==" crossorigin="anonymous" referrerpolicy="no-referrer">
  </script>
  <script src="scripts.js"></script>

</body>



</html>

CSS

* {
  margin: 0;
  padding: 0;
  Box-sizing: border-Box;
}


body {
  background-color:#111111;
  color: white;
}

body::-webkit-scrollbar {
  display: none;
}

.progress-section {
  position: fixed;
  right: 50px;
  top: 40%;
  width: 60px;
  height: 20%;
  display: flex;
  justify-content: space-between;
  will-change: transform;
  transition: 0.3s ease-out;
  z-index: 1;
}

.progress-bar-wrap {
  position: relative;
  width: 1px;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background-color: rgb(70,70,70);
}

.progress-bar {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 0%;
  background-color: rgb(189,189,189);
}

.white {
  background: white;

}


.one {
  background: gray;

}

.two {
  background: green;

}

.three {
  background: blue;

}

.four {
  background: purple;

}
#fullpage {
  height: 1000px;
}

JAVASCRIPT

let progressSection = document.querySelector('.progress-section');
let progressBar = document.querySelector('.progress-bar');
let progressNum = document.querySelector('.progress-num');

let x,y;


function updateProgressBar() {

  progressBar.style.height = `${getScrollPercentage()}%`;
  progressNum.innerText = `${Math.ceil(getScrollPercentage())}%`
  requestAnimationFrame(updateProgressBar)
}

function getScrollPercentage() {
  return ((window.scrollY) / (document.body.scrollHeight - window.innerHeight) * 100)
};

updateProgressBar()


new fullpage('#fullpage',{
  licenseKey: 'LICENSE',autoScrolling: true,scrollBar: true,})



解决方法

您可以使用 fullpage.js state classes

例如:

/* On section 2 slide 0 */
.fp-viewing-page2-0 #nav{ 
   color: red
}

这是一个工作示例: https://codepen.io/alvarotrigo/pen/VwbxbYR

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。