scrollTo函数jQuery不起作用

问题描述 投票:20回答:3

我需要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>
jquery scrollto
3个回答
41
投票

尝试一下

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

FIDDLE


2
投票
/*
* ScrollToElement 1.0
* Copyright (c) 2009 Lauri Huovila, Neovica Oy
*  [email protected]
*  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);

0
投票
 $("#your-div")[0].scrollTo(0, Number.MAX_SAFE_INTEGER);
© www.soinside.com 2019 - 2024. All rights reserved.