[英]AngularJS - Focus on object in nested scroll
So I'm trying to have a nested scroll focus based on a key input. 因此,我试图基于按键输入来实现嵌套滚动焦点。 For this I've used ng-focus
but I seem to have misunderstood it's purpose. 为此,我使用了ng-focus
但是我似乎误解了它的目的。
This JSFiddle shows what I've done so far. 这个JSFiddle显示了我到目前为止所做的。 Whenever a match is found I set ng-focus="x._focus"
to true, and in the console log it shows that this is happening. 每当找到匹配项时,我都将ng-focus="x._focus"
为true,并在控制台日志中显示这正在发生。 But the scroll is not moved to have the input
field in focus. 但是滚动不会移动以使input
字段处于焦点。 How is that? 那个怎么样?
hey i did not really understand what you want , but check this and let me know if this is what you want jsFiddle 嘿,我不是很了解您想要什么,但是请检查一下,让我知道这是否是您想要的jsFiddle
function MyCtrl($scope)
{
$scope.list = []
for(var i = 0; i < 500; i++){
$scope.list.push({
number: i,
_focus: false
})
}
$(document).keypress(function(e)
{
for(var i = 0; i < $scope.list.length; i++)
{
if($scope.list[i].number === e.keyCode)
{
$scope.list[i]._focus = true
console.info('found : ', $scope.list[i])
$scope.$apply(); // Apply changes and change the false to true in dom
$('#nestedScroll').animate(
{
scrollTop: $("#nestedScroll span[scrollTo='true']").offset().top
}, "slow");
return
} else {
$scope.list[i]._focus = false
}
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.