在AngularJS中跟随鼠标的弹出对话框
Popup dialog that follow the mouse in AngularJS
我使用Angular 1.0.6和jQuery,我需要创建一个提示,将跟随鼠标(改变位置)。到目前为止我只有show/hide:
<div ng-repeat="item in items">
<span ng-mouseover="item.show_description=true" ng-mouseleave="item.show_description=false">
{{item.text}}
</span>
<div class="description-popup" ng-show="item.description && item.show_description">
{{item.description}}
</div>
</div>
我应该如何改变x和y位置的弹出依赖于mousemove
事件?我想我可以这样写:
<div pointer="{x: item.x, y: item.y}">Hello</div>
<div class="popup" style="left: {{item.x}}; top: {{item: y}}">
Popup
</div>
但是不知道如何创建这样的指令
我想出了这个可以作为服务使用的实用程序(它需要$parse):
function objectParser(expr) {
var strip = expr.replace(/'s*'{'s*|'s*'}'s*/g, '');
var pairs = strip.split(/'s*,'s*/);
if (pairs.length) {
var getters = {};
var tmp;
for (var i=pairs.length; i--;) {
tmp = pairs[i].split(/'s*:'s*/);
if (tmp.length != 2) {
throw new Error(expr + " is Invalid Object");
}
getters[tmp[0]] = $parse(tmp[1]);
}
return {
assign: function(context, object) {
for (var key in object) {
if (object.hasOwnProperty(key)) {
if (getters[key]) {
getters[key].assign(context, object[key]);
}
}
}
}
}
}
}
这个函数将从object (string)中解析值作为范围值,并且返回的对象将允许基于其他对象更改这些值。它可以在这样的指令中使用:
{
restrict: 'A',
link: function(scope, element, attrs) {
var expr = objectParser(attrs.pointer);
element.mousemove(function(e) {
var offest = element.offset();
scope.$apply(function() {
expr.assign(scope, {
x: e.pageX - offest.left,
y: e.pageY - offest.top
});
});
});
}
};
相关文章:
- 着色引导框对话框
- 文本框不是从Javascript/Asp.net中的对话框中打印出来的
- CKeditor:更改对话框中的默认选择选项
- 搜索api在mac上显示对话框
- 使用密码对话框Javascript请求帮助
- CKEditor v4:自制插件中对话框的动态标题
- 打开相对于鼠标位置的CSS3/HTML5模式对话框
- 在鼠标悬停时保持 JQuery 对话框打开
- jQuery UI 对话框和滚动块竞争鼠标
- 如何使用鼠标移动<对话框>元素
- 禁用模式对话框的鼠标中键
- 关闭jQuery UI对话框上的鼠标点击框外
- jQuery对话框:在鼠标位置打开位置.在firefox中不起作用
- 如何在用户单击鼠标右键时阻止浏览器打开对话框
- 根据用户的鼠标操作,在对话框或新选项卡中显示内容
- JQueryUI:单击鼠标的位置对话框
- 在AngularJS中跟随鼠标的弹出对话框
- jquery ui对话框已停止工作-出现错误“;无法调用方法'鼠标悬停'“未定义”;
- 我如何使对话框聊天日志滚动到底部不断刷新而不改变鼠标焦点
- 鼠标退出和关闭对话框