-1

On button click I want to scroll a specific div. Make sure I don't want to use jQuery.

3
  • Possible duplicate of Scroll / Jump to id without jQuery Commented Sep 13, 2018 at 9:40
  • You can use a hyperlink and a hash fragment. Or you could use one of the solution linked to calculate the position of the element you want to scroll to. Commented Sep 13, 2018 at 9:41
  • 1
    Possible duplicate of Scroll to specific div on (click) in Angular Commented Sep 13, 2018 at 9:41

2 Answers 2

0

You need to use $anchorScroll concept in angular refer example:

'use strict';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();
  };
}]);})(window.angular);

Here 'bottom' is your div id where you want to scroll and 'gotoBottom(). is function on button click

Sign up to request clarification or add additional context in comments.

Comments

0

Give id for that div and use

document.getElementById("id").scrollIntoView();

    <div id="whatever">
       <--do things -->
    </div>
    <script>
        document.getElementById("whatever").scrollIntoView();
    </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.