首頁 > web前端 > js教程 > 主體

jQuery css實作百度百科的頁面導航效果_jquery

WBOY
發布: 2016-05-16 16:26:19
原創
1335 人瀏覽過

這週不小心看到了百度百科的頁面導航效果,感覺挺不錯的,週末抽空寫了下。

下圖為導航部分的效果圖:

css和圖片都是抄百度的,可從百度百科下載。

具體的程式碼如下:

複製程式碼 程式碼如下:




   
   
   
   




   


       
        1
        part1
   

   


        content1,content1
       

























   

   


       
        2
        part2
   

   


        content2,content2
       

























   

   


       
        2-1
        part2-1
   

   


        content2-1,content2-1
       

























   

   


       
        2-2
        part2-2
   

   


        content2-2,content2-2
       

























   

   


       
        3
        part3
   

   


        content,content
       

























   

   


       
        4
        part4
   

   


        content,content
       

























   

   


       
        5
        part5
   

   


        content5,content5
       

























   

   


       
        6
        part6
   

   


        content6,content6
       

























   

   


       
        7
        part7
   

   


        content7,content7
       

























   

   


       
        8
        part8
   

   


        content8,content8
       

























   

   


       
        9
        part9
   

   


        content9,content9
       

























   

   


       
        10
        part10
   

   


        content10,content10
       

























   

   


       
        11
        part11
   

   


        content11,content11
       

























   

   


       
        12
        part12
   

   


        content12,content12
       

























   

   


       
        13
        part13
   

   


        content13,content13
       

























   

   


       
        14
        part14
   

   


        content14,content14
       

























   

   


       
        15
        part15
   

   


        content15,content15
       

























       

























        bottom
   



   

       

           

               

               

           

           

               

               

           

           


               

                   

                        1
                        第1部
                       
                   

                   

                        2
                        第2部
                       
                   

                   

                        2-1
                        part2-1
                       
                   

                   

                        2-2
                        part2-2
                       
                   

                   

                        3
                        第3部
                       
                   

                   

                        4
                        第4部
                       
                   

                   

                        5
                        第5部
                       
                   

                   

                        6
                        第6部
                       
                   

                   

                        7
                        第7部
                       
                   

                   

                        8
                        第8部
                       
                   

                   

                        9
                        第9部
                       
                   

                   

                        10
                        第10部
                       
                   

                   

                        11
                        第11部
                       
                   

                   

                        12
                        第12部
                       
                   

                   

                        13
                        part13
                       
                   

                   

                        14
                        part14
                       
                   

                   

                        15
                        part15
                       
                   

               

           

       

       
       
   





    var SlideInnerHeight = $('#sideCatalog-catalog dl').height();
    var SlideOutHeight = $('#sideCatalog-catalog').height();
    varenableTop=slideInnerHeight-slideOutHeight;
    var 步驟 = 50;
    //點選向上的按鈕
    $('#sideCatalog-down').bind('點選', function () {
        if ($(this).hasClass('sideCatalog-down-enable')) {
            if ((enableTop - Math.abs(parseInt($('#sideCatalog-catalog dl').css('top')))) > 步驟) {
                $('#sideCatalog-catalog dl').stop().animate({'top': '-=' 步驟}, 'fast');
                $('#sideCatalog-up').removeClass('sideCatalog-up-disable').addClass('sideCatalog-up-enable');
            } 其他 {
                $('#sideCatalog-catalog dl').stop().animate({'top': -enableTop}, 'fast');
                $(this).removeClass('sideCatalog-down-enable').addClass('sideCatalog-down-disable');
            }
        } 其他 {
            回復錯誤;
        }
    })
    //點選下方的按鈕
    $('#sideCatalog-up').bind('點選', function () {
        if ($(this).hasClass('sideCatalog-up-enable')) {
            if (Math.abs(parseInt($('#sideCatalog-catalog dl').css('top')) > 步驟) {
                $('#sideCatalog-catalog dl').stop().animate({'top': ' =' 步驟}, 'fast');
                $('#sideCatalog-down').removeClass('sideCatalog-down-disable').addClass('sideCatalog-down-enable');
            } 其他 {
                $('#sideCatalog-catalog dl').stop().animate({'top': '0'}, 'fast');
                $(this).removeClass('sideCatalog-up-enable').addClass('sideCatalog-up-disable');
            }
        } 其他 {
            回復錯誤;
        }
    })

    //點選導覽中的各目錄
    $('#sideCatalog-catalog dl').delegate('dd', 'click', function (e) {
        var index = $(this).index();
        scrollSlide($(this), 索引);
        var ddId = $(this).find('a').stop().attr('href').substring(1);
        var windowTop = $('a[name="' ddId '"]').offset().top;
        $('body,html').animate({scrollTop: windowTop}, 'fast');
        $(this).addClass('heightlight').siblings('dd').removeClass('heightlight');
    })

    //捲動頁面,即捲軸捲動
    $(document).scroll(function () {
        var len = $('.headline-1').length;
        for (var i=len-1; i>=0; i--) {
if ($(this).scrollTop() >= $('.headline-1').eq(i).offset().top - $('.headline-1').eq(i).height( )) {
                var index = i;
                $('#sideCatalog-catalog dl dd').eq(index).addClass('heightlight').siblings('dd').removeClass('heightlight');
                scrollSlide($('#sideCatalog-catalog dl dd').eq(index), index);
                return 稱為;
            } else {
                $('#sideCatalog-catalog dl dd').eq(0).addClass('heightlight').siblings('dd').removeClass('heightlight');
            }
        }
    })

    //導航的捲動,以及向上,向下按鈕的顯示隱藏
    function scrollSlide(that, index){
        if (index             $('#sideCatalog-catalog dl').stop().animate({'top': '0'}, 'fast');
            $('#sideCatalog-down').removeClass('sideCatalog-down-disable').addClass('sideCatalog-down-enable');
            $('#sideCatalog-up').removeClass('sideCatalog-up-enable').addClass('sideCatalog-up-disable');
        } else if (index > 11) {
            $('#sideCatalog-catalog dl').stop().animate({'top': -enableTop}, 'fast');
            $('#sideCatalog-down').removeClass('sideCatalog-down-enable').addClass('sideCatalog-down-disable');
            $('#sideCatalog-up').removeClass('sideCatalog-up-disable').addClass('sideCatalog-up-enable');
        } else {
            var dlTop = parseInt($('#sideCatalog-catalog dl').css('top')) slideOutHeight / 2 - (that.offset().top - $(document)。             $('#sideCatalog-catalog dl').stop().animate({'top': dlTop}, 'fast');
            $('#sideCatalog-down').removeClass('sideCatalog-down-disable').addClass('sideCatalog-down-enable');
            $('#sideCatalog-up').removeClass('sideCatalog-up-disable').addClass('sideCatalog-up-enable');
        }
    }

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板