css - Angular 2-Jquery |使用鼠标位置添加样式(顶部/左侧)

标签 css dynamic typescript angular styles

我正在寻找一种在 Angular 2 中的特定位置(鼠标事件 x/y)添加 div 组件的方法。

https://jsfiddle.net/lennartquerter/w2c7uqw6/

this.xPos = xPos;
this.yPos = yPos;

我将位置传递到我的拒绝类中,但我不知道如何从中制作样式?我检查了 Angular 文档,但我只能设置 bool 值和固定的 css 值/类。我想做这样的事情:

[style]="rejectPosition"

this.rejectPosition = "left: "+ this.xPos + "px ; top: "+ this.yPos + "px;"

但这是不可能的。 是否有 Angular 2 方法可以做到这一点?

我找到了一种不用 reject Component 的方法,它只是用 jQuery 内嵌样式,但我不喜欢这种方法。

最佳答案

[style.left.px]="xPos" [style.top.px]="yPos"

关于css - Angular 2-Jquery |使用鼠标位置添加样式(顶部/左侧),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37372745/

相关文章:

php - 在移动设备上加载时使用 PHP 隐藏元素

angular - 我如何使用 ngRedux 测试服务

c - 动态数组的大小

c - C中结构的动态分配

node.js - TS : Module augmentation, <Type> 仅指类型,但在此处用作值

angular - 将光标放在焦点上输入字段值的末尾 | Angular 2

html - CSS 和 Firefox 有时会出现 Safari 问题

html - 均匀分布菜单

html - 防止固定边栏内的粘性页脚重叠

c# - 如何动态引用 ExpandoObject 中的字段?