scrollTo函数jQuery不工作
我需要Jquery的scrollTo功能来为这个网站工作: 我试过以下方法scrollTo函数jQuery不工作,jquery,scrollto,Jquery,Scrollto,我需要Jquery的scrollTo功能来为这个网站工作: 我试过以下方法 $(document).ready(function() { $("div.btnLp3").click(function(){ $('body,html').scrollTo('#target-examples', 800, {easing:'elasout'}); }); }); 我也试过这个: $(document).ready(function() { $("div.bt
$(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);
});
});
我似乎根本无法让滚动到工作。有人有什么想法吗?以下是我导入的内容:
<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>
试试这个
$("#clickme").click(function() {
$('html, body').animate({
scrollTop: $("#wrap2").offset().top
}, 2000);
return false;
});
我总是喜欢添加一点偏移量,让观众在内容周围有一些喘息的空间。与此类似,.offset().top-20}
这并不能回答用户为什么会出现错误“scrollTo不是函数”的问题。大多数人在搜索“scrollTo不是函数”后会发现这个问题。在回答中,您甚至没有使用问题中的“scrollTo”函数。使用完全不同的函数如何回答op为什么在“scrollTo”上出错的问题?虽然这段代码可能会解决这个问题,但一个好的答案也应该解释它的作用以及它的帮助。对不起,首先,我找到将受scroll影响的目标元素(在本例中,我使用jquery按Id查找元素)
/*
* 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);
$("#your-div")[0].scrollTo(0, Number.MAX_SAFE_INTEGER);