24

この Web サイトで機能するには、Jquery の scrollTo 関数が必要です: http://cinicraft.com/Silverman/index.html

私は次のことを試しました

$(document).ready(function()
{
    $("div.btnLp3").click(function(){
        $('body,html').scrollTo('#target-examples', 800, {easing:'elasout'});
    });
});

そして、私もこれを試しました:

$(document).ready(function()
{
    $("div.btnLp3").click(function(){
        $('html, body').animate({ scrollTop: $(window.location.hash).offset().top}, 1000);
    });
});

まったく仕事ができそうにありませんscrollTo。誰にもアイデアはありますか?インポートしたものは次のとおりです。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">  </script>    
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js">  </script>
4

3 に答える 3

48

これを試して

$("#clickme").click(function() {
    $('html, body').animate({
        scrollTop: $("#wrap2").offset().top
    }, 2000);
    return false;
});

フィドル

于 2013-09-12T02:40:44.787 に答える
3
/*
* ScrollToElement 1.0
* Copyright (c) 2009 Lauri Huovila, Neovica Oy
*  lauri.huovila@neovica.fi
*  http://www.neovica.fi
*  
* Dual licensed under the MIT and GPL licenses.
*/

(function($) {
    $.scrollToElement = function($element, speed) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function(speed) {
        speed = speed || "normal";
        return $.scrollToElement(this, speed);
    };
})(jQuery);
于 2014-04-10T10:10:24.957 に答える