有用于模拟鼠标中心事件的指令吗?
我尝试过寻找一个,但我所找到的只是一个指令,它将一个函数绑定到鼠标上方,或者业力测试用于模拟鼠标以上。
我的用例是,我已经准备好将一个事件绑定到鼠标上,但我正在寻找一个simulate-mouse ="shouldBeMouseOver"形式的指令,以便当$scope.shouldBeMouseOver为真时,我将该指令放在响应上,就像它有mouseenter事件一样。
发布于 2014-12-05 16:18:09
UPTATE!以前的解决方案是一个解决方案。您现在可以使用一个角指令(https://docs.angularjs.org/api/ng/directive/ngMouseenter)。
ng-mouseenter="handler()"以前的解决方案(解决方案)
HTML:
<div simulate-mouse eventhandle="objfromscope">Hover</div> <!-- objfromscope: true or false -->
<div ng-click="objfromscope=!objfromscope">Enable/Disable hover</div>指令
app.directive('simulateMouse', function() {
return {
restrict: 'AE',
scope: {
eventhandle : '=eventhandle' //eventhandle is two way data binded
},
link: function(scope, element, attrs) {
scope.$watch(function() {
return scope.eventhandle;
}, function(newValue) {
console.log(newValue)
if(newValue){
element.off("mouseenter").on("mouseenter",function(){
onMouseOverCall()
});
}else{
element.off("mouseenter");
}
});
var onMouseOverCall = function(){ /* called only when eventhandle is true */
console.log("hoho")
}
}
};
});https://stackoverflow.com/questions/27319228
复制相似问题