在可滚动的 div angularjs 中滚动到顶部
scroll to top inside a scrollable div angularjs
这个问题已经被问过很多次了,但大多数都没有得到回答,而且我试过的一些解决方案也没有奏效。
在我的页面 (angularjs) 中,只有左半部分可滚动,我将其放在 div 元素中。现在如何在可滚动 div.
中实现滚动到顶部
对于整个页面,我可以使用以下代码完成
/** scroll to top function */
$scope.scrollToTop = function($var) {
$('html, body').animate({
scrollTop: 0
}, 'fast');
};
我要如何修改它才能只在左侧滚动到顶部
试试这个:
$('html, body').animate(
{scrollTop: $('#your-element').position().top} , '600', function() {
return false;
}
);
这是一个工作示例:
http://jsfiddle.net/4wdfb6cu/
尝试像 class 或 id
那样做
$('sample').animate({
scrollTop:0
},'fast');
这个问题已经被问过很多次了,但大多数都没有得到回答,而且我试过的一些解决方案也没有奏效。
在我的页面 (angularjs) 中,只有左半部分可滚动,我将其放在 div 元素中。现在如何在可滚动 div.
中实现滚动到顶部对于整个页面,我可以使用以下代码完成
/** scroll to top function */
$scope.scrollToTop = function($var) {
$('html, body').animate({
scrollTop: 0
}, 'fast');
};
我要如何修改它才能只在左侧滚动到顶部
试试这个:
$('html, body').animate(
{scrollTop: $('#your-element').position().top} , '600', function() {
return false;
}
);
这是一个工作示例: http://jsfiddle.net/4wdfb6cu/
尝试像 class 或 id
那样做$('sample').animate({
scrollTop:0
},'fast');