• 侧面导航


    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    div,body{
    padding: 0;
    margin: 0;
    }
    .header{
    100%;
    height: 1000px;
    background: palegoldenrod;
    }
    .page{
    100%;
    height:300px;
    }
    div{
    text-align: center;
    line-height: 300px;
    font-size: 50px;
    }
    .page:nth-child(2n){
    background: red;
    }
    .page:nth-child(2n+1){
    background: yellowgreen;
    }
    .footer{
    100%;
    height:500px;
    background: palevioletred;
    }
    ul li{
    list-style: none;
    80px;
    height:40px;
    border:1px solid #666;
    background: greenyellow;
    text-align: center;
    line-height: 40px;
    }
    ul{
    position: fixed;
    top:30%;
    left:2%;
    z-index: 1654;
    display: none;
    }
    .ul .current{
    background: white;
    }
    </style>
    </head>
    <body>
    <div class="header"></div>
    <div class="page">1</div>
    <div class="page">2</div>
    <div class="page">3</div>
    <div class="page">4</div>
    <div class="page">5</div>
    <div class="page">6</div>
    <div class="footer">ding</div>
    <ul class="ul">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>ding</li>
    </ul>
    </body>
    <script src="modules/jquery.min.js"></script>
    <script>
    $(function(){
    $('li:last').on('click',function(){//点击ding回顶部
    $('html,body').animate({scrollTop:0},200);
    });
    var $header_h = $('.header').outerHeight();//获取头部的外部高度
    /*console.log($header_h);*/
    $(window).on('scroll',function(){
    var $h = $(window).scrollTop();//获取滚动条当前的值
    console.log($h);
    if ($h >= $header_h) {//如果当前滚动条的位置大于或等于头部的高度
    $('.ul').fadeIn();//那么ul淡入
    } else {
    $('.ul').fadeOut();//否则ul淡出
    }
    $switch($h);
    });
    $('.ul>li').on('click', function () {//给ul下面的每个li添加点击事件
    var $index = $(this).index();//设置一个$index变量并且把当前点击的li的下标值付给它
    var $section=$current_top($index);
    console.log($section)
    $('html,body').animate({//浏览器视口的相对滚动条顶部的偏移的动画效果
    scrollTop: $section
    }, 200);
    });
    })
    function $current_top($index){
    //设置一个变量$section并把点击一个li后当前一个section的滚动条偏移后的位置的值付给它
    var $section = $('.page').eq($index).offset().top-300;
    //给当前点击的li赋予类名current,并且移除与他同辈元素siblings()li的类名;
    $('.ul>li').eq($index).addClass('current').siblings().removeClass('current');
    return $section;
    }
    function $switch($h){
    switch (true) {
    case $h >= $current_top(5):
    break;
    case $h >= $current_top(4):
    break;
    case $h >= $current_top(3):
    break;
    case $h >= $current_top(2):
    break;
    case $h >= $current_top(1):
    break;
    case $h >= $current_top(0):
    break;
    }
    }
    </script>
    </html>
  • 相关阅读:
    asp.net 曲线图
    asp.net 图片下载
    使用a标签删除进行提示
    asp.net 后台获取input的值
    asp.net Excel数据导入到数据库中
    asp.net DataSet数据导出到Excel中
    select top 所有
    asp.net 上一条和下一条记录的显示
    日期相减函数
    mybatis mapper学习1(补充)-mapper.xml映射文件生成补充
  • 原文地址:https://www.cnblogs.com/wen936/p/7597163.html
Copyright © 2020-2023  润新知