Angular 2 - Jquery | Adding styles (top/left) with a mouse position

有些话、适合烂在心里 提交于 2019-12-23 09:19:59

问题


I'm looking for a way to add a div component in Angular 2 at a specific place (mouse event x/y).

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

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

i pass the position into my reject class, but i do not know how to make styles out of it ? I checked angular docs but i can only set booleans and fixed css values / classes. I would like to do something like this:

[style]="rejectPosition"

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

But its not possible. Is there a Angular 2 way to do this?

I found a way to do it without the reject Component, that just styles it inline with jQuery, but i do not like this approach.


回答1:


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


来源:https://stackoverflow.com/questions/37372745/angular-2-jquery-adding-styles-top-left-with-a-mouse-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!