2017-05-21 2 views
0

この小さなスニペットのコードでScrollTo関数を使用しようとしていますので、ページがページ「0」の先頭ではなくID divタグにスクロールします。どんな助けでも大歓迎です!ScrollTo:ページの先頭ではなく#divタグ

ここでは、ページの上部にスクロールするためのコードを示します。すべての作品はちょうど上に行くよりdivの場所に追加する方法を把握する必要があります。

私も、私はsmoothstate.jsに助けを

本当にありがとうございましたを使用しています言及する必要があります:)

$(function(){ 
    'use strict'; 
    var $body = $('html,body, #smoothState'); 
    var options = { 
    prefetch: true, 
    cacheLength: 2, 
    blacklist: ".no-smoothstate a, .post-edit-link, a[href*='.jpg'], a[href*='.png'], a[href*='.jpeg'], a[href*='.pdf']", 

onStart: { 
    duration: 0, // Duration of our animation 
    render: function ($container) { 
     $('.spinner').fadeIn(0); 
    // Add your CSS animation reversing class 
    $container.addClass('is-exiting'); 




    $body.animate({ 
      scrollTop: 0 
     }); 
    // Restart your animation 
    smoothState.restartCSSAnimations(); 
    } 
}, 




onReady: { 
    duration: 0, 
    render: function ($container, $newContent) { 
     $('.spinner').fadeOut(0); 
    // Remove your CSS animation reversing class 
    $container.removeClass('is-exiting'); 



    // Inject the new content 
    $container.html($newContent); 



    } 
    }, 

答えて

1

ここでは、私は今それをやっている方法です。うまく動作しているようだ。これは自分自身のようにjQueryでプロではない他の人たちを助けてくれることを願っています:)

$('html, body').animate({ 
scrollTop: $("#target-element").offset().top 
}, 1000); 
関連する問題