jQuery: jump to next

前端 未结 5 1010
無奈伤痛
無奈伤痛 2021-01-24 00:34

So this should be fairly basic... and I\'m doing it, but I wanted to ask for a few different options.

One option is using the \"Smooth Scroll\" and anchor names... but I

相关标签:
5条回答
  • 2021-01-24 01:09

    so you're wanting to scroll up and down the page depending on which link the user clicks on?

    from my experience, the jQuery.ScrollTo plugin is the best for this. Easy to use and a lot of support

    http://flesler.blogspot.com/2007/10/jqueryscrollto.html

    0 讨论(0)
  • 2021-01-24 01:12

    I managed to get an awesome smooth scroll using mootools for my 'jump to next' having not liked the jaggedness of the jquery ones. It also works in unison with the other jquery on the page once you do a little tweaking.

    http://davidwalsh.name/smooth-scroll-mootools

    The site I use it on is currently under construction but here's the link http://ggszabo/new/indexb.html

    Click the section ribbons to view.

    0 讨论(0)
  • 2021-01-24 01:19

    Look into the scrollTo jQuery plugin, it should meet your needs fully.

    0 讨论(0)
  • 2021-01-24 01:22

    You could try just setting the scrolltop

    var doc = (document.contentWindow || document).document || document.ownerDocument || document,
        el = ($.browser.webkit) ? doc.body : doc.documentElement;
    
    $(el).scrollTop($('#services').offset().top);
    
    0 讨论(0)
  • 2021-01-24 01:28
    jQuery.fn.extend({
      scrollTo : function(speed, easing) {
        return this.each(function() {
          var targetOffset = $(this).offset().top;
          $('html,body').animate({scrollTop: targetOffset}, speed, easing);
        });
      }
    });
    
    // Scroll to "about" section
    $('#about').scrollTo('fast', 'linear');
    

    Update - To jump from section to section use a simple event handler:

    JQuery:

    $('.next-section').click(function(){
        var $this = $(this),
            $next = $this.parent().next();
    
        $next.scrollTo($next.offset().top, 500, 'linear');
    });
    
    $('.prev-section').click(function(){
        var $this = $(this),
            $prev = $this.parent().prev();
    
        $prev.scrollTo($prev.offset().top, 500, 'linear');
    });
    

    HTML:

    <section id="about">
        <a href="#" class="prev-section">Previous Section</a>
        <a href="#" class="next-section">Next Section</a>
        <div class="section-content">
            Foobar
        </div>
    </section>
    

    Here's a demo: http://jsfiddle.net/AlienWebguy/Xdg2k/

    0 讨论(0)
提交回复
热议问题