9

I have a div like below:

<div class="col-xs-1 scroll-button"><i class="glyphicon glyphicon-chevron-left"></i> </div>
<div class="customer-ust-bant col-xs-22" id="letters">
    <box ng-repeat="lt in alph" name="{{lt}}" id="{{lt}}"></box>
</div>
<div class="col-xs-1 scroll-button" ng-click="gotoBottom()"><i class="glyphicon glyphicon-chevron-right"></i> </div>

and box template:

<div class="alphabet-kutu">{{name|uppercase}}</div>

and the directive:

app.directive("box", function() {
return {
    restrict:"E",
    scope:{
        name:"@"
    },
    templateUrl:"/static/templates/customers/box.html",
    link:function(scope,elem,attrs,ctrl) {

    }
  };
})

As you see I have div containing letters in alphabet and styled in horizontal scroll.

When a button is clicked i want to scroll this div to left.

 $scope.gotoBottom = function (){
var element = angular.element( document.querySelector( '#letters' ) );
    element.animate({scrollLeft: element.offset().left}, "slow");
    //element.scrollLeft(100);

};

I tried animate and scrollLeft functions. But I did not do any good. Is there a special function in AngularJS for this situations? How do I scroll a div to left using jQuery?

4
  • Do you need to scroll the content inside the box or move the box to the left? Commented Apr 11, 2014 at 16:15
  • 1
    angular.element doesn't have an animate method Commented Apr 11, 2014 at 16:30
  • @Blazemonger if he include jQuery, element will be jQuery object. Commented Apr 11, 2014 at 16:33
  • @jcubic scroll the content Commented Apr 11, 2014 at 16:37

1 Answer 1

3

I think you should give another value to your scrollLeft. Because in the given code, you are trying to scroll the element to its current location, so it won't move. For example:

element.animate({scrollLeft: element.offset().left - 50}, "slow");

PS: Please ensure you have jQuery included. The subset of jQuery embedded in angularJS does not seem to support animate function

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

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.