更改不同轮播上的导航栏字体颜色

时间:2017-02-19 12:55:18

标签: javascript jquery html css

我真的不知道如何处理这个问题所以请求帮助我!

我在这个项目中有一个整页滑块(在主页上)。在滑块内我有5个不同图片的项目。

我想更改第一张幻灯片/轮播项目上导航栏文字的颜色,其余部分看起来相同。首先应该是灰色的,在最后4个幻灯片中,导航栏的文本应该是白色的。

我还想更改导航栏中的徽标(在第一张幻灯片上它应该是灰色的,在最后4张幻灯片上它也应该是白色的。我有2个png来完成这项工作。)

以下是2张图片,用于展示我想要做的事情: slider1 slider2 (rest of sliders)

HTML:

<nav id="mainNav" class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="navbarmargin container-fluid">
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span><img src="muszerfal_elements/img/menu2.png" style="max-width: 38px; padding-right: 4px; margin-top: 6px;"/>
            </button>
            <a class="navbar-brand page-scroll" href="index.html">
                <img class="logo" src="img/final_2.png">
            </a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1" >
            <ul class="navbartext nav navbar-nav navbar-right">
                <li>
                    <a href="works.html">Works</a>
                </li>
                <li>
                    <a href="personal.html">Personal</a>
                </li>
                <li>
                    <a href="about.html">About</a>
                </li>
                <li>
                    <a href="contact.html">Contact</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- Full Page Image Background Carousel Header -->
<header id="carousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
        <li data-target="#carousel" data-slide-to="0" class="active"></li>
        <li data-target="#carousel" data-slide-to="1"></li>
        <li data-target="#carousel" data-slide-to="2"></li>
        <li data-target="#carousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for Slides -->
    <div class="carousel-inner">
        <div class="item active">
            <!-- Set the first background image using inline CSS below. -->
            <div class="fill" style="background-image:url('img/slider_1.jpg');" alt="Slide 1"></div>
            <div class="carousel-caption caption1">
                <h2>Fashion</h2>
            </div>
        </div>
        <div class="item">
            <!-- Set the second background image using inline CSS below. -->
            <div class="fill" style="background-image:url('img/slider_3.jpg');" alt="Slide 2"></div>
            <div class="carousel-caption caption2">
                <h2>Fashion</h2>
            </div>
        </div>
        <div class="item">
            <!-- Set the third background image using inline CSS below. -->
            <div class="fill" style="background-image:url('img/slider_4.jpg');" alt="Slide 3"></div>
            <div class="carousel-caption caption3">
                <h2>Beauty</h2>
            </div>
        </div>
        <div class="item">
            <!-- Set the third background image using inline CSS below. -->
            <div class="fill" style="background-image:url('img/slider_5.jpg');" alt="Slide 3"></div>
            <div class="carousel-caption caption4">
                <h2>Fine Art</h2>
            </div>
        </div>
    </div>

</header> 

你能帮我解决一下这个问题吗?

提前谢谢!

3 个答案:

答案 0 :(得分:1)

我认为你要做的是类似于fullPage.js,它允许整页滑块,我相信使用一些基本的CSS你可以实现所需的更改颜色功能。 http://alvarotrigo.com/fullPage/#firstPage

答案 1 :(得分:0)

.carousel-inner&gt; .item:first-child h2 {color:black;}

答案 2 :(得分:0)

我假设这是你正在使用的滑块:https://github.com/BlackrockDigital/startbootstrap-full-slider

更改第一张幻灯片上文本的颜色不是问题(参见下面的示例)。但是,我不认为这个滑块有一个回调函数可以返回它所在的幻灯片。这将需要根据您所在的幻灯片更改导航栏的字体颜色。因此,我认为您必须寻找另一个允许您执行此操作的整页滑块。

&#13;
&#13;
/*
 * Start Bootstrap - Full Slider (http://startbootstrap.com/)
 * Copyright 2013-2016 Start Bootstrap
 * Licensed under MIT (https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE)
 */

html,
body {
  height: 100%;
}

.carousel,
.item,
.active {
  height: 100%;
}

.carousel-inner {
  height: 100%;
}


/* Background images are set within the HTML using inline CSS, not here */

.fill {
  width: 100%;
  height: 100%;
  background-position: center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  background-size: cover;
  -o-background-size: cover;
}

footer {
  margin: 50px 0;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="author" content="">

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

  <title>Full Slider - Start Bootstrap Template</title>

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

  <!-- Navigation -->
  <nav id="mainNav" class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="navbarmargin container-fluid">
      <div class="navbar-header page-scroll">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span><img src="http://placehold.it/25x25" style="max-width: 38px; padding-right: 4px; margin-top: 6px;"/>
            </button>
        <a class="navbar-brand page-scroll" href="index.html">
          <img class="logo" src="http://placehold.it/25x25">
        </a>
      </div>

      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="navbartext nav navbar-nav navbar-right">
          <li>
            <a href="works.html">Works</a>
          </li>
          <li>
            <a href="personal.html">Personal</a>
          </li>
          <li>
            <a href="about.html">About</a>
          </li>
          <li>
            <a href="contact.html">Contact</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>


  <!-- Full Page Image Background Carousel Header -->
  <header id="carousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#carousel" data-slide-to="0" class="active"></li>
      <li data-target="#carousel" data-slide-to="1"></li>
      <li data-target="#carousel" data-slide-to="2"></li>
      <li data-target="#carousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for Slides -->
    <div class="carousel-inner">
      <div class="item active">
        <!-- Set the first background image using inline CSS below. -->
        <div class="fill" style="background-image:url('http://placehold.it/1900x1080/ffffff');" alt="Slide 1"></div>
        <div class="carousel-caption caption1" style="color: grey;">
          <h2>Fashion (this text is grey)</h2>
        </div>
      </div>
      <div class="item">
        <!-- Set the second background image using inline CSS below. -->
        <div class="fill" style="background-image:url('http://placehold.it/1900x1080');" alt="Slide 2"></div>
        <div class="carousel-caption caption2">
          <h2>Fashion (this text is white)</h2>
        </div>
      </div>
      <div class="item">
        <!-- Set the third background image using inline CSS below. -->
        <div class="fill" style="background-image:url('http://placehold.it/1900x1080');" alt="Slide 3"></div>
        <div class="carousel-caption caption3">
          <h2>Beauty</h2>
        </div>
      </div>
      <div class="item">
        <!-- Set the third background image using inline CSS below. -->
        <div class="fill" style="background-image:url('http://placehold.it/1900x1080');" alt="Slide 3"></div>
        <div class="carousel-caption caption4">
          <h2>Fine Art</h2>
        </div>
      </div>
    </div>

  </header>

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

  <!-- Script to Activate the Carousel -->
  <script>
    $('.carousel').carousel({
      interval: 5000 //changes the speed
    })
  </script>

</body>

</html>
&#13;
&#13;
&#13;