1. <small id='rAQoT'></small><noframes id='rAQoT'>

    1. <tfoot id='rAQoT'></tfoot>

        <bdo id='rAQoT'></bdo><ul id='rAQoT'></ul>
    2. <legend id='rAQoT'><style id='rAQoT'><dir id='rAQoT'><q id='rAQoT'></q></dir></style></legend>
    3. <i id='rAQoT'><tr id='rAQoT'><dt id='rAQoT'><q id='rAQoT'><span id='rAQoT'><b id='rAQoT'><form id='rAQoT'><ins id='rAQoT'></ins><ul id='rAQoT'></ul><sub id='rAQoT'></sub></form><legend id='rAQoT'></legend><bdo id='rAQoT'><pre id='rAQoT'><center id='rAQoT'></center></pre></bdo></b><th id='rAQoT'></th></span></q></dt></tr></i><div id='rAQoT'><tfoot id='rAQoT'></tfoot><dl id='rAQoT'><fieldset id='rAQoT'></fieldset></dl></div>

      jQuery 使用下一个/上一个按钮滚动到下一个 div 类

      jQuery Scroll to Next Div Class with Next / Previous Button(jQuery 使用下一个/上一个按钮滚动到下一个 div 类)
        <bdo id='HgpVU'></bdo><ul id='HgpVU'></ul>
          <tbody id='HgpVU'></tbody>

        <small id='HgpVU'></small><noframes id='HgpVU'>

        <legend id='HgpVU'><style id='HgpVU'><dir id='HgpVU'><q id='HgpVU'></q></dir></style></legend>

              1. <tfoot id='HgpVU'></tfoot>

              2. <i id='HgpVU'><tr id='HgpVU'><dt id='HgpVU'><q id='HgpVU'><span id='HgpVU'><b id='HgpVU'><form id='HgpVU'><ins id='HgpVU'></ins><ul id='HgpVU'></ul><sub id='HgpVU'></sub></form><legend id='HgpVU'></legend><bdo id='HgpVU'><pre id='HgpVU'><center id='HgpVU'></center></pre></bdo></b><th id='HgpVU'></th></span></q></dt></tr></i><div id='HgpVU'><tfoot id='HgpVU'></tfoot><dl id='HgpVU'><fieldset id='HgpVU'></fieldset></dl></div>
                本文介绍了jQuery 使用下一个/上一个按钮滚动到下一个 div 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想要的是固定导航,使用 NEXT 和 PREV 按钮基本上将页面滚动到具有section"类的下一个 div.

                What I'd like is for the fixed navigation, with NEXT and PREV buttons to basically scroll the page to the next div with the class of "section".

                我已经设置 jQuery 实质上为 NEXT 和 PREV href 添加了一个点击功能.然后这个点击函数将使用 ScrollTop 移动到具有 .section 类的下一个 duv.

                I've setup jQuery to essentially add a click function to the NEXT and PREV hrefs. This click function will then use ScrollTop to move to the next duv with a class of .section.

                这里是 jQuery:

                Here is the jQuery:

                $('div.section').first();
                // binds a click event-handler to a elements whose class='display'
                $('a.display').on('click', function(e) {
                    // prevents the default action of the link
                    e.preventDefault();
                    // assigns the text of the clicked-link to a variable for comparison purposes
                    var t = $(this).text(),
                      that = $(this);
                      console.log(that.next())    
                      // checks if it was the 'next' link, and ensures there's a div to show after the currently-shown one
                      if (t === 'next' && that.next('div.section').length > 0) {
                      //Scroll Function
                      $('html, body').animate({scrollTop:that.next('div.section').scrollTop()});
                  } 
                    // exactly the same as above, but checking that it's the 'prev' link
                    else if (t === 'prev' && that.prev('div.section').length > 0) {
                      //Scroll Function
                       $('html, body').animate({scrollTop:that.prev('div.section').scrollTop()});     
                  }
                });
                

                我目前正在使用带有大量评论的 jQuery 开发 JSfiddle,以帮助您消化:http://jsfiddle.net/ADsKH/1/

                I am currently working on JSfiddle with heavily commented jQuery to help you digest: http://jsfiddle.net/ADsKH/1/

                我有一个 console.log 目前正在检查 (that.next()) 以确定下一个 .section 将是什么,但它给了我一些非常奇怪的结果.

                I have a console.log currently checking for (that.next()) to determine what the next .section will be, but it's giving me back some very weird results.

                为什么这没有按预期工作?

                Why this isn't working as intended?

                推荐答案

                你的 that 找不到 .next('.section') 因为它嵌套在里面.navigation.

                Your that can't find a .next('.section') because it's nested inside .navigation.

                来自 .next() 的 jQuery 文档.

                From the jQuery documentation for .next().

                获取匹配元素集中每个元素的紧随其后的兄弟.

                Get the immediately following sibling of each element in the set of matched elements.

                这是一个基于您的代码的工作示例

                这篇关于jQuery 使用下一个/上一个按钮滚动到下一个 div 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                <i id='xzNp6'><tr id='xzNp6'><dt id='xzNp6'><q id='xzNp6'><span id='xzNp6'><b id='xzNp6'><form id='xzNp6'><ins id='xzNp6'></ins><ul id='xzNp6'></ul><sub id='xzNp6'></sub></form><legend id='xzNp6'></legend><bdo id='xzNp6'><pre id='xzNp6'><center id='xzNp6'></center></pre></bdo></b><th id='xzNp6'></th></span></q></dt></tr></i><div id='xzNp6'><tfoot id='xzNp6'></tfoot><dl id='xzNp6'><fieldset id='xzNp6'></fieldset></dl></div>

                  1. <small id='xzNp6'></small><noframes id='xzNp6'>

                  2. <legend id='xzNp6'><style id='xzNp6'><dir id='xzNp6'><q id='xzNp6'></q></dir></style></legend><tfoot id='xzNp6'></tfoot>
                      <bdo id='xzNp6'></bdo><ul id='xzNp6'></ul>

                            <tbody id='xzNp6'></tbody>