如何使用AngularJS将div向左滚动

can*_*mik 9 css jquery angularjs

我有一个如下所示的div:

<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>
Run Code Online (Sandbox Code Playgroud)

和框模板:

<div class="alphabet-kutu">{{name|uppercase}}</div>
Run Code Online (Sandbox Code Playgroud)

和指令:

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

    }
  };
})
Run Code Online (Sandbox Code Playgroud)

如你所见,我有div包含字母表中的字母和水平滚动样式.

单击按钮时,我想将此div向左滚动.

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

};
Run Code Online (Sandbox Code Playgroud)

我尝试了animate和scrollLeft函数.但我没有做任何好事.在这种情况下,AngularJS中是否有特殊功能?如何使用jQuery将div向左滚动?

Ham*_*uss 3

我认为你应该给你的scrollLeft另一个值。因为在给定的代码中,您试图将元素滚动到其当前位置,所以它不会移动。例如:

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

PS:请确保您已包含 jQuery。AngularJS中嵌入的jQuery子集似乎不支持animate函数