zoukankan      html  css  js  c++  java
  • 滚轮滚动一定距离触发导航顶部固定,且所点击的关键词,背景字体变色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="scrollto,jquery" />
    <meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" />
    <title>滚轮滚动一定距离触发导航顶部固定,且所点击的关键词,背景字体变色</title>
    <style type="text/css">
    /* 固定导航 */
    .x_menu{
    background: #fff;
    padding:10px 0;
    100%;
    z-index: 1;
    }
    .x_menu ul li{float:left;margin-right:15px;list-style:none}
    .x_menu ul li a{
    110px;
    height: 40px;
    text-align: center;
    line-height: 38px;
    font-size: 20px;
    border:1px solid #3daf36;
    color: #3daf36;
    border-radius: 30px;
    display: inline-block;
    text-decoration: none;
    margin-right: 5px;
    }
    .x_menu ul li a:hover{background: #3daf36;color: #fff;}
    .x_on{
    background: #3daf36;
    color: #fff!important;
    }
    .x_fixed{position: fixed;top: 0;border-bottom: 1px solid #3daf36;}
    </style>

    </head>

    <body>
    <div style="100%;background:pink;height:700px;"></div>
    <div class="x_menu">
    <div class="container">
    <ul class="list-inline">
    <li><a class="x_on x-cpts" href="#x-cpts">产品特色</a></li>
    <li><a class="x-shfw" href="#x-shfw">售后服务</a></li>
    <li><a class="x-yhzc" href="#x-yhzc">用户支持</a></li>
    <li><a class="x-khal" href="#x-khal">客户案例</a></li>
    <li><a class="x-cpzx" href="#x-cpzx">产品资讯</a></li>
    <li><a class="x-gyxz" href="#x-gyxz">关于心智</a></li>
    <li><a class="x-xgtj" href="#x-xgtj">相关推荐</a></li>
    <li><a class="x-lxwm" class="nomargin" href="#x-lxwm">联系我们</a></li>
    </ul>
    </div>
    </div>
    <div style="height:700px;"></div>
    </body>
    <script type="text/javascript" src="jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="jquery.scrollTo.js"></script>
    <script type="text/javascript">
    //导航选中背景变色
    $('.x_menu ul li a').click(function(){
    $(this).addClass('x_on').parent().siblings().find('a').removeClass('x_on');
    });
    //固顶
    $(window).scroll(function() {
    var top = $(window).scrollTop();
    if(top>=450){
    $(".x_menu").addClass("x_fixed");
    }else{
    $(".x_menu").removeClass("x_fixed");
    }
    });
    </script>
    </html>

  • 相关阅读:
    设计模式——创建型设计模式总结(简单工厂、普通工厂、抽象工厂、建造者、原型和单例)
    网易游戏2011招聘笔试题+答案解析
    华为2011上机笔试题2+参考程序
    趋势科技2011校招笔试题+答案解析
    腾讯2012实习生笔试题2+答案解析
    浙商银行2011笔试题+答案解析
    Linux学习笔记(三)——权限管理
    PowerShell在多个文件中检索关键字
    Linux学习笔记(一)——入门
    PowerShell函数调用问题
  • 原文地址:https://www.cnblogs.com/fkcqwq/p/6972051.html
Copyright © 2011-2022 走看看