Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scroll bottom of div using angular js

I have a div in which I added element .I want to scroll to bottom of the div whenever element added in div.I know how to do in in jquery .But I did not know how to scroll using angular js I know using jquery Scroll to bottom of div?

testCaseContainer is id of div .

var elem = document.getElementById('testCaseContainer'); // just to
                                                                    // scroll down
                                                                    // the line
        elem.scrollTop = elem.scrollHeight;

I want to know how it is possible using angular ?

http://plnkr.co/edit/M8tCL8Szc3h3FatFLycG?p=preview

I added css in div container so that it scroll .

.heightClass{
  height:100px;
  overflow :auto;
}

how to move focus below when item is added ..please post your answer..

like image 759
Shruti Avatar asked Aug 17 '14 09:08

Shruti


People also ask

How do I scroll to the bottom of a div?

In jQuery, we can automatically use the scrollTop() and height() methods to scroll a page from top to bottom. For example, JQuery scroll to the bottom of div set the scrollTop property of a div's JavaScript to the value of scroll height property to scroll to the bottom of div.

How do I scroll a div?

For vertical scrollable bar use the x and y axis. Set the overflow-x:hidden; and overflow-y:auto; that will automatically hide the horizontal scroll bar and present only vertical scrollbar. Here the scroll div will be vertically scrollable.

How do I scroll to the bottom of the page?

also Hot key Ctrl +End will take you directly to the bottom of the page.

How do you scroll to the bottom in CSS?

use css position top keep it at the bottom {position : relative; bottom:0;} .


1 Answers

You could create your own scroll directive that watches a collection, and when it changes, sets the scroll position:

app.directive('scroll', function($timeout) {
  return {
    restrict: 'A',
    link: function(scope, element, attr) {
      scope.$watchCollection(attr.scroll, function(newVal) {
        $timeout(function() {
         element[0].scrollTop = element[0].scrollHeight;
        });
      });
    }
  }
});

HTML

<div class="heightClass" scroll="studentDetail">

Note: $timeout is needed to ensure that the scroll position is set after the view is rendered.

Demo Plunker

like image 57
pixelbits Avatar answered Oct 05 '22 12:10

pixelbits