2011-10-26 8 views
1

これはかなり基本的なはずです...私はそれをやっていますが、いくつかのオプションを求めていました。jQuery:次へジャンプ<section>

「スムーススクロール」とアンカーの名前を使用しているオプションが1つありますが、それはかなり矛盾しています。

これは私のHTML構造である:

<section id="home"> 
<!-- some content --> 
</section> 

<section id="about"> 
<!-- some content --> 
</section> 

<section id="services"> 
<!-- some content --> 
</section> 

... 

私はセクションの右側にいくつかの「クイックボタン」を持っており、基本的には上下セクションへのセクションから「移動」することができます。

+3

あなたの質問は何ですか? – Birey

+0

私はそれが明らかだと思った: "しかし、私はいくつかのオプションを求めていました。"私が言ったように、私は「滑らかなスクロール」と呼ばれるオプションを使用していますが、少し矛盾しています。 – dcolumbus

答えて

0

scrollTo jQueryプラグインを見ると、あなたのニーズを完全に満たすはずです。

5
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'); 

更新 - 単純なイベントハンドラを使用するセクションからセクションへジャンプする:

は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> 

はここでデモです:http://jsfiddle.net/AlienWebguy/Xdg2k/

+0

にスクロールすることができるようにするためにありがとうございます...特定のボタンにスクロール機能を追加するだけでなく、私はまた、 "

"から "
" – dcolumbus

+0

更新されたコードスニペットを表示 – AlienWebguy

+0

更新されたコードをありがとうございます。それはうまく動作しますが、それが緩和されないという事実を除いて... – dcolumbus

0

あなただけのscrollTopスプライトに

var doc = (document.contentWindow || document).document || document.ownerDocument || document, 
    el = ($.browser.webkit) ? doc.body : doc.documentElement; 

$(el).scrollTop($('#services').offset().top); 
0

を設定してみてください可能性があり、私は次の私の「ジャンプのためMooToolsのを使用して素晴らしいスムーズスクロールを得ることができましたjqueryもののギザギザが好きではない。もう少し微調整を行うと、ページ上の他のjqueryと一貫して動作します。

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

私はそれを使用するサイトは現在建設中であるが、ここに表示するセクションのリボンをクリックしてリンクhttp://ggszabo/new/indexb.html

です。

+0

whoops ...サイトはhttp://ggszabo.com/new/indexb.htmlです。 – Szabotage

関連する問題