导航条问题

导航条问题

# 具体遇到的问题

导航条添加“header_status_back”类之后 但是导航条里面的文字没变变成白色,js中元素样式可以被添加上但是里面内容颜色没有发生变化


# 报错信息的截图
http://img1.sycdn.imooc.com//climg/5fb4d8ba09d2f53613200498.jpg

# 相关课程内容截图
http://img1.sycdn.imooc.com//climg/5fb4d8e4094497a312780558.jpg

# 尝试过的解决思路和结果

# 粘贴全部相关代码,切记添加代码注释(请勿截图)

/*

BEM 设计模式


模块(没有前缀,多个单词用 - 连接)

元素(元素在模块之后,可以有多个层级,以 __ 连接)

修饰(某元素、或者某模块特别的状态,必须有一个状态名和状态值,使用 _ 链接)


*/


.header {

  background-color#f7f7f7;

}

.header__wrap {

  positionrelative;

  margin0 auto;

  width1200px;

  height80px;

}

.header__logo {

  positionabsolute;

  top50%;

  left20px;

  margin-top-19px;

  width150px;

  height38px;

  font-size20px;

  line-height38px;

  color#07111b;

  text-indent50px;

  backgroundurl("../img/logo.png"no-repeat left center;

  background-size38px 38px;

}

.header__nav {

  positionabsolute;

  right20px;

  top50%;

  margin-top-19px;

  height38px;

}

.header__nav-item {

  positionrelative;

  floatleft;

  displayblock;

  margin-left40px;

  height38px;

  line-height38px;

  font-size14px;

  color#292f35;

}

.header__nav-item:hover {

  color#f01400;

}

.header__nav-item_status_active {

  color#f01400;

}

.header__nav-item_status_active::after {

  content" ";

  displayblock;

  width100%;

  height2px;

  positionabsolute;

  background-color#f01400;

  left0;

  bottom0;

}

.header__nav-item_custom_button {

  width90px;

  color#f4f4f5;

  text-aligncenter;

  background-color#000;

  border-radius3px;

  -webkit-border-radius3px;

  -moz-border-radius3px;

  -ms-border-radius3px;

  -o-border-radius3px;

}

/* 第一屏 */

.screen-1 {

  positionrelative;

  height800px;

  backgroundurl("../img/bg-screen-1.png"center center;

  background-sizecover;

}

.screen-1__heading {

  margin0;

  padding152px 0 0 0;

  font-size46px;

  font-weightnormal;

  text-aligncenter;

  color#4d555d;

}

.screen-1__heading b {

  font-weightnormal;

  color#f01400;

}

.screen-1__phone {

  positionabsolute;

  left50%;

  bottom180px;

  margin-left-687px;

  width1375px;

  height305px;

  backgroundurl("../img/screen-1-phone.png"no-repeat center center;

  z-index2;

}

.screen-1__shadow {

  positionabsolute;

  left50%;

  bottom30px;

  margin-left-616px;

  width1233px;

  height411px;

  backgroundurl("../img/screen-1-shadow.png"no-repeat center center;

  z-index1;

  opacity0.8;

}

/* 第二屏 */

.screen-2 {

  positionrelative;

  height800px;

  background-color#fafafa;

  overflowhidden;

}

.screen-2__heading {

  margin0;

  padding96px 0 0 0;

  font-size46px;

  line-height46px;

  font-weightnormal;

  text-aligncenter;

  color#f01400;

}

.screen-2__subheading {

  margin0;

  padding25px 0 0 0;

  font-size14px;

  line-height28px;

  font-weightnormal;

  text-aligncenter;

  color#2c313c;

}

.screen-2__phone {

  positionabsolute;

  left50%;

  bottom-345px;

  margin-left-464px;

  width928px;

  height873px;

  backgroundurl("../img/screen-2-phone.png"no-repeat center center;

  z-index2;

}

.screen-2__point {

  positionabsolute;

  padding-right112px;

  width108px;

  height22px;

  font-size22px;

  line-height22px;

  color#4d555d;

  backgroundurl("../img/icon-point-right.png"no-repeat center right;

}

.screen-2__point__custom_right {

  padding0 0 0 112px;

  backgroundurl("../img/icon-point-left.png"no-repeat center left;

}

.screen-2__point_i_1 {

  top150px;

  left-164px;

}

.screen-2__point_i_2 {

  top30px;

  right130px;

}

.screen-2__point_i_3 {

  top330px;

  right30px;

}

/* 第三屏 */

.screen-3 {

  positionrelative;

  height800px;

  backgroundurl("../img/bg-screen-3.png"center center;

  background-sizecover;

  overflowhidden;

}

.screen-3__wrap {

  positionrelative;

  margin0 auto;

  width1200px;

  heightauto;

}

.screen-3__heading {

  padding-top94px;

  font-size46px;

  line-height46px;

  text-alignleft;

  color#fff;

}

.screen-3__subheading {

  padding-top25px;

  font-size14px;

  line-height28px;

  text-alignleft;

  color#fff;

}

.screen-3__phone {

  positionabsolute;

  top195px;

  right0;

  bottom-345px;

  width750px;

  height873px;

  backgroundurl("../img/screen-3-phone.png"no-repeat center top;

  z-index2;

}

.screen-3__features {

  positionabsolute;

  top395px;

  left0;

  width324px;

  height280px;

}

.screen-3__features__item {

  floatleft;

  margin0 20px 20px 0;

  width138px;

  height118px;

  text-aligncenter;

  border1px solid #cb7173;

  border-radius3px;

  -webkit-border-radius3px;

  -moz-border-radius3px;

  -ms-border-radius3px;

  -o-border-radius3px;

  color#fff;

}

.screen-3__features__item__number {

  padding28px 0 8px;

  height36px;

  font-size36px;

  line-height36px;

}

.screen-3__features__item__desc {

  height14px;

  font-size14px;

  line-height14px;

}

/* 第四屏 */


.screen-4 {

  positionrelative;

  height800px;

  background-color#fff;

  overflowhidden;

}

.screen-4__wrap {

  positionrelative;

  margin0 auto;

  width1200px;

  heightauto;

}

.screen-4__heading {

  padding-top135px;

  font-size46px;

  line-height46px;

  text-aligncenter;

  color#f01400;

}

.screen-4__subheading {

  padding-top29px;

  font-size14px;

  line-height28px;

  text-aligncenter;

  color#464a4f;

}

.screen-4__type {

  positionabsolute;

  top304px;

  width1260px;

  height270px;

  margin-left40px;

}

.screen-4__type__item {

  width220px;

  margin-right90px;

  height270px;

  floatleft;

  positionrelative;

  text-aligncenter;

  background-sizecover;

}

.screen-4__type__item_i_1 {

  backgroundurl(../img/phone-1.pngno-repeat left top;

}

.screen-4__type__item_i_2 {

  backgroundurl(../img/phone-2.pngno-repeat left top;

}

.screen-4__type__item_i_3 {

  backgroundurl(../img/phone-3.pngno-repeat left top;

}

.screen-4__type__item_i_4 {

  backgroundurl(../img/phone-4.pngno-repeat left top;

}

.screen-4__type__item__color {

  width100%;

  height14px;

  line-height14px;

  font-size14px;

  color#2c3238;

  positionabsolute;

  bottom-44px;

}

.screen-4__type__item__storage {

  width100%;

  height12px;

  line-height12px;

  font-size12px;

  color#a4a9a1;

  positionabsolute;

  bottom-66px;

}


/* 第五屏 */

.screen-5 {

  positionrelative;

  height800px;

  background-color#d9dde1;

  overflowhidden;

}

.screen-5__bg {

  width1920px;

  height433px;

  backgroundurl("../img/bg-screen-5.png"no-repeat center;

  background-sizecontain;

  positionabsolute;

  bottom-100px;

  left50%;

  margin-left-960px;

}

.screen-5__heading {

  padding-top130px;

  font-size46px;

  line-height46px;

  text-aligncenter;

  color#f01400;

}

.screen-5__subheading {

  padding-top29px;

  font-size14px;

  line-height28px;

  text-aligncenter;

  color#464a4f;

}

/* 第六屏 */

.screen-buy {

  positionrelative;

  /* height: 320px; */

  height80px;

  padding120px 0 120px 0;

  background#2b333b url("../img/bg-screen-buy.png"no-repeat center center;

  background-sizecover;

  overflowhidden;

  text-aligncenter;

}

.screen-buy__button {

  displayinline-block;

  height80px;

  width240px;

  font-size24px;

  line-height80px;

  text-aligncenter;

  color#fff;

  background-color#f01414;

  border-radius3px;

  -webkit-border-radius3px;

  -moz-border-radius3px;

  -ms-border-radius3px;

  -o-border-radius3px;

  /* 为hover效果添加一个效果 使得hover不这么生硬 */

  transitionall 0.5s;

  -webkit-transitionall 0.5s;

  -moz-transitionall 0.5s;

  -ms-transitionall 0.5s;

  -o-transitionall 0.5s;

}

.screen-buy__button:hover {

  box-shadow0 0 10px rgba(0000.5);

}

/* 底部 */

.footer {

  height80px;

  text-aligncenter;

  color#fff;

  font-size12px;

  line-height80px;

  background-color#07111b;

}


/* outline css */

.outline {

  positionfixed;

  padding5px 10px;

  bottom120px;

  right0;

  z-index3;

  background-color#fff;

  box-shadow0 4px 12px rgba(0000.5);

}

.outline__item {

  displayblock;

  width40px;

  height30px;

  line-height30px;

  padding5px 0;

  background-color#fff;

  margin-top5px;

  border-top1px solid #eee;

  color#939992;

}

.outline__item:first-child {

  bordernone;

}

.outline__item:active {

  color#f01400;

}


/* 导航条样式设置 */

.header {

  transitionall 1s;

  -webkit-transitionall 1s;

  -moz-transitionall 1s;

  -ms-transitionall 1s;

  -o-transitionall 1s;

}

.header_status_back {

  positionfixed;

  top0;

  left0;

  right0;

  backgroundrgba(0000.5);

  z-index3;

}

.header_status_black .header__nav-item,

.header_status_black .header__logo {

  color#fff;

}

.header_status_black .header__nav-item_status_active {

  colorred;

}

.header_status_black .header__nav-item:hover {

  transitionall 1s;

  colorred;

}


/* 大纲出现 */

.outline {

  transformtranslate(100%0);

  transitionall 1s;

}


.outline_status_in {

  transformtranslate(00);

}


.outline__item {

  transitionall 1s;

}



js

/*

1.页面载入完成后所有的动画元素设置_animate_init

2.页面滚动到某一屏 开始播放动画/导航条,大纲出现

3.导航条,大纲联动(双向定位-滚动导航条定位/大纲定位)

4.导航条滑动门特效

*/

// 1


// 获取元素

var getElem = function (selector) {

    return document.querySelector(selector);

}

var getAllElem = function (selector) {

    return document.querySelectorAll(selector);

}

// 获取元素的样式

var getCls = function (element) {

    return element.getAttribute('class');

  }

// 设置元素的样式

var setCls = function (elementcls) {

    return element.setAttribute('class'cls)

}

// 为元素添加样式

var addCls = function (elementcls) {

    var baseCls = getCls(element);

    if (baseCls.indexOf(cls=== -1) {

        setCls(element, baseCls + " " + cls)

    }

    return;

}


// 为元素删除样式

var delCls = function (elementcls) {

    var baseCls = getCls(element);

    if (baseCls.indexOf(cls!= -1) {

        setCls(element, baseCls.split(cls).join(' ').replace(/\s+/g' '));

    }

    return;

}


// 1.初始化样式init


var screenAnimateElements = {

    '.screen-1': [

        '.screen-1__heading',

        '.screen-1__phone',

        '.screen-1__shadow'

    ],

    '.screen-2': [

        '.screen-2__heading',

        '.screen-2__subheading',

        '.screen-2__phone',

        '.screen-2__point_i_1',

        '.screen-2__point_i_2',

        '.screen-2__point_i_3',

    ],

    '.screen-3': [

        '.screen-3__heading',

        '.screen-3__phone',

        '.screen-3__subheading',

        '.screen-3__features',

    ],

    '.screen-4': [

        '.screen-4__heading',

        '.screen-4__subheading',

        '.screen-4__type__item_i_1',

        '.screen-4__type__item_i_2',

        '.screen-4__type__item_i_3',

        '.screen-4__type__item_i_4',

    ],

    '.screen-5': [

        '.screen-5__heading',

        '.screen-5__subheading',

        '.screen-5__bg',

    ]

}

function setScreenAnimateInit(screenCls) {

    var screen = document.querySelector(screenCls);  // 获取当前屏的元素

    var animateElements = screenAnimateElements[screenCls];// 获取需要设置动画的元素

    for (var i = 0; i < animateElements.length; i++) {

        var element = document.querySelector(animateElements[i]);

        var baseCls = element.getAttribute('class');

        // console.log(baseCls);

        element.setAttribute('class', baseCls + ' ' + animateElements[i].substr(1+ '_animate_init');

    }

}

window.onload = function () {

    // 为所有元素设置init

    for (k in screenAnimateElements) {

        setScreenAnimateInit(k);

    }

    console.log('load');

}


// 2.滚动到哪就播放到哪

// 滚动条设置

function playScreenAnimateDone(screenCls) {

    var screen = document.querySelector(screenCls);  // 获取当前屏的元素

    var animateElements = screenAnimateElements[screenCls];// 获取需要设置动画的元素

    for (var i = 0; i < animateElements.length; i++) {

        var element = document.querySelector(animateElements[i]);

        var baseCls = element.getAttribute('class');

        // console.log(baseCls);

        element.setAttribute('class', baseCls.replace('_animate_init''_animate_done'));

    }

}

window.onscroll = function () {

    var top = document.documentElement.scrollTop || document.body.scrollTop;

    if (top > 100) {

        addCls(getElem('.header'), 'header_status_back');

        playScreenAnimateDone('.screen-1');

    } else {

        delCls(getElem('.header'), 'header_status_back');

    }

    if (top > 400) {

        addCls(getElem('.outline'), 'outline_status_in');

    } else {

        delCls(getElem('.outline'), 'outline_status_in');

    }

    if (top > (800 * 1-100)) {

        playScreenAnimateDone('.screen-2');


    }

    if (top > (800 * 2-100)) {

        playScreenAnimateDone('.screen-3');

    }

    if (top > (800 * 3-100)) {

        playScreenAnimateDone('.screen-4');

    }

    if (top > (800 * 4-100)) {

        playScreenAnimateDone('.screen-5');

    }

}


// 3.导航条,大纲联动(双向定位-滚动导航条定位/大纲定位)

// 导航条点击页面跳转

var navItems = getAllElem('.header__nav-item');

var setNavJump = function(i,lib) {

    var elem = lib[i];

    elem.onclick = function() {

        document.body.scrollTop=i*800;

    }

}

for (var i = 0; i < navItems.length; i++) {

    setNavJump(i,navItems);

}


​html

<html>


<head>

    <meta charset="utf-8">

    <title>慕课手机</title>

    <link rel="stylesheet" type="text/css" href="./css/base.css" />

    <link rel="stylesheet" type="text/css" href="./css/index.css" />

    <link rel="stylesheet" type="text/css" href="./css/animate.css" />

</head>


<body>

    <header class="header">

        <div class="header__wrap">

            <div class="header__logo">慕课手机</div>

            <nav class="header__nav">

                <a href="javascript:;" class="header__nav-item">首页</a>

                <a href="javascript:;" class="header__nav-item">外观</a>

                <a href="javascript:;" class="header__nav-item">配置</a>

                <a href="javascript:;" class="header__nav-item">型号</a>

                <a href="javascript:;" class="header__nav-item">说明</a>

                <a href="javascript:;" class="header__nav-item header__nav-item_custom_button">立即购买</a>

            </nav>

        </div>

    </header>

    <div class="screen-1">

        <h2 class="screen-1__heading"><b>慕课手机</b> 让你的生活更精彩</h2>

        <div class="screen-1__phone"></div>

        <div class="screen-1__shadow"></div>

    </div>

    <div class="screen-2">

        <h2 class="screen-2__heading">优美的设计,更令人着迷</h2>

        <h3 class="screen-2__subheading">采用受欢迎的设计,让它更加出色。<br>

            款式小巧、轻便手感更舒适。绚丽高清的显示屏,整个外观显得格外精致。</h3>

        <div class="screen-2__phone">

            <div class="screen-2__point screen-2__point_i_1">高清摄像</div>

            <div class="screen-2__point screen-2__point__custom_right screen-2__point_i_2">超薄机身</div>

            <div class="screen-2__point screen-2__point__custom_right screen-2__point_i_3">大屏显示</div>

        </div>

    </div>

    <div class="screen-3">

        <div class="screen-3__wrap">

            <h2 class="screen-3__heading">外形小巧,功能强大的手机</h2>

            <h3 class="screen-3__subheading">采用受欢迎的设计,让它更加出色。<br>

                款式小巧、轻便手感更舒适。绚丽高清的显示屏,整个外观显得格外精致。</h3>

            <div class="screen-3__phone"></div>

            <div class="screen-3__features">

                <div class="screen-3__features__item">

                    <div class="screen-3__features__item__number">5.7</div>

                    <div class="screen-3__features__item__decs">英寸大屏</div>

                </div>

                <div class="screen-3__features__item">

                    <div class="screen-3__features__item__number">1200</div>

                    <div class="screen-3__features__item__decs">万像素</div>

                </div>

                <div class="screen-3__features__item">

                    <div class="screen-3__features__item__number">3D</div>

                    <div class="screen-3__features__item__decs">touch</div>

                </div>

                <div class="screen-3__features__item">

                    <div class="screen-3__features__item__number">A9</div>

                    <div class="screen-3__features__item__decs">处理器</div>

                </div>

            </div>


        </div>

    </div>

    <div class="screen-4">

        <div class="screen-4__wrap">

            <h2 class="screen-4__heading">丰富的手机型号</h2>

            <h3 class="screen-4__subheading">找到适合你的手机</h3>

            <div class="screen-4__type">

                <div class="screen-4__type__item screen-4__type__item_i_1">

                    <div class="screen-4__type__item__color">慕课红</div>

                    <div class="screen-4__type__item__storage">32G/64G/128G</div>

                </div>

                <div class="screen-4__type__item screen-4__type__item_i_2">

                    <div class="screen-4__type__item__color">土豪金</div>

                    <div class="screen-4__type__item__storage">32G/64G/128G</div>

                </div>

                <div class="screen-4__type__item screen-4__type__item_i_3">

                    <div class="screen-4__type__item__color">太空灰</div>

                    <div class="screen-4__type__item__storage">32G/64G/128G</div>

                </div>

                <div class="screen-4__type__item screen-4__type__item_i_4">

                    <div class="screen-4__type__item__color">绅士黑</div>

                    <div class="screen-4__type__item__storage">32G/64G/128G</div>

                </div>

            </div>

        </div>

    </div>

    <div class="screen-5">

        <div class="screen-5__heading">游戏、学习、拍照,有这一部就够了</div>

        <div class="screen-5__subheading">看视频、拍摄高清视频与照片、视频聊天、通话相结合,一机多功能,让您生活更丰富精彩。

        </div>

        <div class="screen-5__bg"></div>

    </div>

    <div class="screen-buy">

        <a href="javascript:;" class="screen-buy__button">立即购买</a>

    </div>

    <footer class="footer">© 2016 imooc.com 京ICP备13046642号</footer>


    <div class="outline">

        <a href="javascript:;" class="outline__item">首页</a>

        <a href="javascript:;" class="outline__item">外观</a>

        <a href="javascript:;" class="outline__item">配置</a>

        <a href="javascript:;" class="outline__item">型号</a>

        <a href="javascript:;" class="outline__item">说明</a>

    </div>

    <script src="js/test.js"></script>

    <script src="js/index.js"></script>

</body>


</html>


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

​同学你好,类名写的不对。加在元素上的类名为header_status_back,而css中写的是.header_status_black,back多了一个字母l,建议:去掉字母l,如下:

http://img1.sycdn.imooc.com//climg/5fb639780963d5a106230133.jpg

祝学习愉快~

  • MiMicccc 提问者 #1
    原来如此!谢谢老师
    2020-11-19 19:02:55
好帮手慕言 2020-11-18 18:09:16

同学你好,在同学提供的代码中,没有给导航项设置字体颜色的样式,建议:给导航项添加样式,例如:
http://img1.sycdn.imooc.com//climg/5fb4f22c09a6353805770126.jpg

祝学习愉快~

  • 提问者 MiMicccc #1
    .header_status_black .header__nav-item, .header_status_black .header__logo { color: #fff; } 老师我添加了这个样式啊
    2020-11-19 16:47:04
  • 提问者 MiMicccc #2
    上面css里面有这个样式。。。。。。。。。
    2020-11-19 16:48:31
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师