久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

單頁導航菜單 - 活動指示器

Single page navigation menu - active indicator(單頁導航菜單 - 活動指示器)
本文介紹了單頁導航菜單 - 活動指示器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 jQuery 航點更新單頁網站的導航.

I'm trying to update the navigation for a single page website using jQuery waypoints.

我想根據當前視圖中的部分更新導航.使用導航鏈接向下時效果很好.我的問題是,當您嘗試滾動到當前部分上方的部分時,查看活動錨點位于應位于的位置下方.

I want to update the navigation based on the current section in view. It works fine when going down using the navigation links. My problem is when you try to scroll to a section above the current section in view the active anchor is one below where it should be.

請看我的演示.

jQuery

$(document).ready(function(){
        $('section').waypoint(function(direction) {
          thisId = $(this).attr('id');
          $('ul li').each(function(){
            var secondaryID = $(this).attr('class');
            if  ( secondaryID == thisId )
                {
                    $('ul li').removeClass('active');
                    $(this).addClass('active');
                }
            });
    },{offset: '0'});   
}); 
$('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'') 
        || location.hostname == this.hostname) {

        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
           if (target.length) {
             $('html,body').animate({
                 scrollTop: target.offset().top
            }, 500);
            return false;
        }
    }
});

HTML

<ul>
    <li class="test"><a href="#test"></a></li>
    <li class="test2"><a href="#test2"></a></li>
    <li class="test3"><a href="#test3"></a></li>
    <li class="test4"><a href="#test4"></a></li>
    <li class="test5"><a href="#test5"></a></li>
</ul>
<section id="test"></section>
<section id="test2"></section>
<section id="test3"></section>
<section id="test4"></section>
<section id="test5"></section>

更新

我使用兩個具有不同偏移量的航路點函數來實現這一點,但這顯然不是最佳解決方案.

I got this to work using two waypoint functions with different offsets but this is clearly not the best solution.

http://jsfiddle.net/SJkmh/10/

我試圖找到一種在同一函數中指定偏移量的方法(取決于方向),我使用了一個值為 (1 & -1) 的偏移量變量,但不幸的是它只使用了 +1.

I trying to find a way of specifying offsets from within the same function (depending on direction), I used a variable for offset with values of (1 & -1), but unfortunately it only uses +1.

http://jsfiddle.net/SJkmh/13/

推薦答案

試試這個:你的修改示例

$(document).ready(function(){
        $('section').waypoint(function(direction) {
          var me = $(this); //added
          thisId = $(this).attr('id');
          $('ul li').each(function(){
            var secondaryID = $(this).attr('class');
            if  ( secondaryID == thisId )
                {
                    $('ul li').removeClass('active');

                    //added
                    if(direction==='up'){
                        me = $(this).prev();
                    }

                    //added
                    if(!me.length){
                        me = $(this);
                    }

                    $(this).addClass('active');
                }
            });
    },{offset: '0'});   
}); 

UPD好的,這個例子怎么樣:

想法是:

1) 當我們點擊 section N 上邊框時,向下滾動時,表示活動部分變為 section N + 1.

1) When we hit section N top border, while scrolling down, means active section become section N + 1.

2) 當我們點擊 section N 上邊框時,同時滾動頂部,意味著 section N 變為活動狀態.

2) When we hit section N top border, while scrolling top, means section N become active.

PS.對不起我的英語

Javascript

$(document).ready(function(){
        $('section').waypoint(function(direction) {
            var activeSection = $(this);
            if(direction === 'down'){
                activeSection = $(this).next();
            }
            //activeSection = $(this);
            var sectionId   = activeSection.attr('id');
            $('ul li').removeClass('active');
            $('ul li.' + sectionId).addClass('active');
            console.log(activeSection);
        });
}); 

$('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'') 
        || location.hostname == this.hostname) {

        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
           if (target.length) {
             $('html,body').animate({
                 scrollTop: target.offset().top - (target.height() / 5)
            }, 500);
            return false;
        }
    }
});

這篇關于單頁導航菜單 - 活動指示器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 51ⅴ精品国产91久久久久久 | 午夜在线视频一区二区三区 | 亚洲视频在线看 | 精品一二三区 | 亚洲精品久久久久中文字幕欢迎你 | 最新黄色毛片 | 日韩视频精品 | 69av片| 久久久久国产一区二区三区四区 | av黄色免费在线观看 | 区一区二在线观看 | 午夜tv免费观看 | 久久青| 特黄视频 | 日韩小视频在线 | 国产97久久 | 成人性视频免费网站 | 国产精品久久久久久久久久免费 | 日本a视频| 久久久久久久久久久久久九 | 精品久久影院 | 成人亚洲| 99精品国产一区二区三区 | 国产成人精品综合 | 中文字幕一区在线观看视频 | 久久99国产精品 | 97精品超碰一区二区三区 | 欧美一区2区三区3区公司 | 国产精品久久国产精品久久 | 欧美黑人又粗大 | 国产一区二区电影 | 欧美区日韩区 | 国产精品观看 | 嫩草最新网址 | 国产精品久久久爽爽爽麻豆色哟哟 | 欧美成人在线免费 | 精品久久电影 | 亚洲综合国产精品 | 色黄爽| 中文字幕一区二区三区不卡 | 亚洲一本 |