Javascript 如何在angularjs中滚动到div
当我点击一个按钮时,我试图滚动到我的标签栏 我的html(选项卡)Javascript 如何在angularjs中滚动到div,javascript,html,angularjs,scroll,mean,Javascript,Html,Angularjs,Scroll,Mean,当我点击一个按钮时,我试图滚动到我的标签栏 我的html(选项卡) 到目前为止这还不错,但我的身高是固定的。有谁能建议我如何直接滚动到div。谢谢。这是Angular的一项特别服务,AnchorScroll 以下是角度文档中的一个示例: <div id="scrollArea" ng-controller="ScrollController"> <a ng-click="gotoBottom()">Go to bottom</a> <a id="
到目前为止这还不错,但我的身高是固定的。有谁能建议我如何直接滚动到
div
。谢谢。这是Angular的一项特别服务,AnchorScroll
以下是角度文档中的一个示例:
<div id="scrollArea" ng-controller="ScrollController">
<a ng-click="gotoBottom()">Go to bottom</a>
<a id="bottom"></a> You're at the bottom!
</div>
angular.module('anchorScrollExample', [])
.controller('ScrollController', ['$scope', '$location', '$anchorScroll',
function($scope, $location, $anchorScroll) {
$scope.gotoBottom = function() {
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
};
}]);
倒下
你在底部!
角度模块('anchorScrollExample',[])
.controller('ScrollController'、['$scope'、'$location'、'$anchorScroll',
功能($scope、$location、$anchorScroll){
$scope.gotoBottom=函数(){
//将location.hash设置为的id
//要滚动到的元素。
$location.hash('bottom');
//致电$anchorScroll()
$anchorScroll();
};
}]);
试试这个代码
$(“#上移”)。单击(函数(){
$(“html,body”).stop().animate({
scrollTop:$(“#制表符”).offset().top-40
}“500”、“线性”);
});代码>
#选项卡{
高度:900px;
背景色:#ccc;
}
#上移{
位置:固定;
字体大小:24px;
底部:25px;
右:25px;
高度:10px;
宽度:10px;
颜色:红色;
}
---这里的所有代码--
向上的
您应该重命名“如何使用angularJS和jQuery滚动到div”这是用于滚动到目的地的官方文档
function ScrollTopForTabs(){
$timeout(function () {
$('html, body').animate({
scrollTop: 650
}, 1000);
}, 1000);
}
<div id="scrollArea" ng-controller="ScrollController">
<a ng-click="gotoBottom()">Go to bottom</a>
<a id="bottom"></a> You're at the bottom!
</div>
angular.module('anchorScrollExample', [])
.controller('ScrollController', ['$scope', '$location', '$anchorScroll',
function($scope, $location, $anchorScroll) {
$scope.gotoBottom = function() {
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
};
}]);