[英]DOM Element in directive
I have three panels and want to know which panel is on foucs how do I know that? 我有三个面板,想知道foucs上的哪个面板,我怎么知道呢?
I want to ask which element is right on foucs and then i want to add a Class. 我想问哪个元素是正确的,然后我想添加一个类。
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);
}
};
});
Also not working: document.getElementById('panel1'); 同样不起作用:document.getElementById('panel1');
my html: 我的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>
thank you in advance. 先感谢您。
I think the inner function was a bit irritating. 我认为内部功能有点令人讨厌。 Now you can see that i just want to know which element is the current one.
现在您可以看到我只想知道哪个元素是当前元素。
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);
}
};
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.