Javascript 指令中的DOM元素

Javascript 指令中的DOM元素,javascript,angularjs,directive,Javascript,Angularjs,Directive,我有三个小组,想知道foucs上有哪个小组,我怎么知道 我想问foucs上哪个元素是正确的,然后我想添加一个类 myApp.directive('myDir', function ($rootScope, $interval) { return { restrict: 'A', scope: { } link: function (scope, element, attrs) { $interval(function () {

我有三个小组,想知道foucs上有哪个小组,我怎么知道

我想问foucs上哪个元素是正确的,然后我想添加一个类

myApp.directive('myDir', function ($rootScope, $interval) {
return {
    restrict: 'A',
    scope: {
    }
    link: function (scope, element, attrs) {
        $interval(function () {
            var data = element[0].getBoundingClientRect();

            for (var i = 0; i < $rootScope.gazePoints.length; i++) {
                var x = $rootScope.gazePoints[i].x;
                var y = $rootScope.gazePoints[i].y;
                if (x >= data.left && x <= data.right && y >= data.top && y < data.bottom) {  

                    var look = element.children('panel1');
                    if (look == element) // is not working
                    {
                        console.log("found")
                        element.addClass('onFocus');
                    }             
                }
            }

          }, 3000);
        }
     };
  });
myApp.directive('myDir',函数($rootScope,$interval){
返回{
限制:“A”,
范围:{
}
链接:函数(范围、元素、属性){
$interval(函数(){
变量数据=元素[0]。getBoundingClientRect();
对于(变量i=0;i<$rootScope.gazePoints.length;i++){
var x=$rootScope.gazePoints[i].x;
变量y=$rootScope.gazePoints[i].y;
如果(x>=data.left&&x=data.top&&y
也不起作用:document.getElementById('panel1')

我的html:

<div class="container" my-dir></div>
        <div class="panel panel-primary" id='panel1'>
               <div class="panel-body">
                        Panel content1
               </div>
         </div>
         <div class="panel panel-primary" id='panel2'>
               <div class="panel-body">
                        Panel content2
               </div>
         </div>
         <div class="panel panel-primary" id='panel3'>
               <div class="panel-body">
                        Panel content3
               </div>
         </div>
 </div> 

小组内容1
小组内容2
小组内容3

提前谢谢。

我觉得内部功能有点烦人。现在你可以看到,我只想知道哪个元素是当前元素

myApp.directive('myDir', function ($rootScope, $interval) {
return {
restrict: 'A',
scope: {
}
link: function (scope, element, attrs) {
    $interval(function () {

       var look = element; // the current but how do I know which panel???


      }, 3000);
    }
 };

}))

我不确定我是否理解正确。焦点和模糊是输入字段事件。当用户单击其中一个选项卡时,可以添加类。这就是你想要达到的目标吗?不,我不是真的想“聚焦”,我只是想知道哪个元素是当前元素。因为我有三个面板。我不知道如何才能知道链接中的哪个元素是当前元素您是否使用getBoundingClientRect()在手机/平板电脑上获得这种“聚焦”效果?不,仅在普通桌面上。我正在使用眼动跟踪器,想分析用户在看什么