我创建了一个 AngularJS 应用程序,当您在输入框中键入多个字符时,它会过滤输入框下的列表。这个输入框位于页面的中间,我希望它在用户输入时跳转到页面顶部。我不确定如何实现这一目标。我对 jquery 和 Angular 还很陌生,所以任何帮助都将不胜感激
问问题
77 次
2 回答
0
I would create a directive for you input field. Something like this:
.directive('query', function() {
return {
restrict:"A",
replace: true,
template: "<input type='text' ng-model='query'>",
link: function(scope, elem) {
elem.bind('input', function() {
elem.css({'top':'10px','position':'fixed'});
});
}
}
});
Then you can just stick <div query></div>
wherever your original input field was. I tested it and it worked well for me. Directives are the angular way to DOM manipulations like this. Best of luck.
于 2013-08-05T17:37:57.273 回答
0
尝试这个
$('html, body').animate({ scrollTop: 0 }, 'slow');
每当用户键入 watch for the event 时转到页面顶部
$scope.watch('mg-model',function(val){
};)
当 val 为 null 或为空时,将文本框内的任何 div id 包装起来并设置动画
于 2013-08-05T16:33:04.877 回答