更改不同部分的标题背景

时间:2017-07-15 11:55:15

标签: javascript jquery html css fullpage.js



<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.4/jquery.fullpage.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.4/jquery.fullpage.extensions.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.4/jquery.fullpage.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<header>
      <div class="header-top clearfix">
        <a href="getinvolved.html" class="pull-right btn btn-danger btn-round  donate">DONATE NOW</a>
        <img src="img/logo.png" class="img-responsive" />
        <a class="l-right toggle-menu" href="#" id="pop">
          <span class="icon-menu" ></span>
        </a>
      </div>

      <div class="menu-overlay">
        <div class="menu-body">
          <a href="#"><span class="closer" onclick="closeNav()"><i class="icon-close icons"></i></span></a>
          <ul class="menu-pan">
            <li><a href="index.html">Home</a></li>
            <li><a href="about.html">About Us</a></li>
            <li><a href="whatwedo.html">What We Do</a></li>
            <li><a href="getinvolved.html">Get Involved</a></li>
            <li><a href="contactus.html">Contact Us</a></li>
          </ul>
        </div>
      </div>
    </header>
    
    
    <div id="fullpage">
      <section class="vertical-scrolling" id="section1">
      
      </section>
      <section class="vertical-scrolling" id="section2">
      
      </section>
      
      <section class="vertical-scrolling" id="section2">
      
      </section>
      
      <section class="vertical-scrolling" id="section3">
      
      </section>
      <section class="vertical-scrolling" id="section4">
      
      </section>
      
      <section class="vertical-scrolling" id="section5">
      
      </section>
      
      </div>
      
      
&#13;
&#13;
&#13; 您好我正在为我的网站使用fullpage.js模板。我正在使用现有的菜单条形码fullpage.js模板。我想更改特定部分的标题背景。当我滚动到第三部分时,我想更改为将标题背景更改为白色。

1 个答案:

答案 0 :(得分:0)

试试这个:

var top1 = $('#section1').offset().top;
var top2 = $('#section2').offset().top;
var top3 = $('#section3').offset().top;
var top4 = $('#section4').offset().top;
var top5 = $('#section5').offset().top;

$(document).scroll(function() {
  var scrollPos = $(document).scrollTop();
  if (scrollPos >= top1 && scrollPos < top2) {
    $('#change').css('background-color', '#f00');
  } else if (scrollPos >= top2 && scrollPos < top3) {
    $('#change').css('background-color', '#0f0');
  } else if (scrollPos >= top3 && scrollPos < top4) {
    $('#change').css('background-color', '#00f');
  } else if (scrollPos >= top4 && scrollPos < top5) {
    $('#change').css('background-color', '#000');
  }else if (scrollPos >= top5) {
    $('#change').css('background-color', '#ff0000');
  }
});
body {
  margin: 0;
  padding-top: 30px
}
header {
  position: fixed;
  top: 0;
  width: 100%;
  height: 30px;
  background-color: #000;
}
ul{
  list-style-type:none;
  padding: 0px;
  margin: 0px;
}
ul li{
  display: inline-block;
  padding: 5px;
}
section {
  height: 500px;
  background-color: #aaa;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header id="change">
  <div class="container">
    <ul>
        <li><a href="index.html">Home</a></li>
        <li><a href="about.html">About Us</a></li>
        <li><a href="whatwedo.html">What We Do</a></li>
        <li><a href="getinvolved.html">Get Involved</a></li>
        <li><a href="contactus.html">Contact Us</a></li>
    </ul>
  </div>
</header>

<section id="section1">Content</section>
<section id="section2">Content</section>
<section id="section3">Content</section>
<section id="section4">Content</section>
<section id="section5">Content</section>

根据您的需要更改内容和Css。