admin管理员组文章数量:1424632
I am trying to scroll to my tabs bar when I click on a button
My html(tabs)
<div class="col-xs-12" id="tabs">
---All the code here----
</div>
My js,
function ScrollTopForTabs(){
$timeout(function () {
$('html, body').animate({
scrollTop: 650
}, 1000);
}, 1000);
}
This was fine up to now but I was given a fixed height. Can anyone please suggest me how to scroll top to div
directly.Thanks.
I am trying to scroll to my tabs bar when I click on a button
My html(tabs)
<div class="col-xs-12" id="tabs">
---All the code here----
</div>
My js,
function ScrollTopForTabs(){
$timeout(function () {
$('html, body').animate({
scrollTop: 650
}, 1000);
}, 1000);
}
This was fine up to now but I was given a fixed height. Can anyone please suggest me how to scroll top to div
directly.Thanks.
- You should rename "How to scroll to div with angularJS and jQuery" – Thomas Decaux Commented May 23, 2017 at 21:00
- Here is the official documentation for scrolling to a destination docs.angularjs/api/ng/service/$anchorScroll – 120DEV Commented Aug 12, 2017 at 11:49
2 Answers
Reset to default 2Is a special service in Angular for this, AnchorScroll.
Here is an example from Angular documentation:
<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();
};
}]);
try this code
$("#moveup").click(function(){
$("html, body").stop().animate({
scrollTop: $('#tabs').offset().top - 40
}, '500', 'linear');
});
#tabs{
height:900px;
background-color:#ccc;
}
#moveup{
position:fixed;
font-size:24px;
bottom:25px;
right:25px;
height:10px;
width:10px;
color:red;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div class="col-xs-12" id="tabs">
---All the code here----
<a id="moveup">up</a>
</div>
本文标签: javascriptHow to scroll to div in angularjsStack Overflow
版权声明:本文标题:javascript - How to scroll to div in angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744663151a2618370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论