scrollTo函数jQuery无法正常工作

时间:2013-09-12 01:48:50

标签: jquery scrollto

我需要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>

3 个答案:

答案 0 :(得分:36)

试试这个

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

FIDDLE

答案 1 :(得分:2)

/*
* 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);

答案 2 :(得分:1)

 $("#your-div")[0].scrollTo(0, Number.MAX_SAFE_INTEGER);
相关问题