Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CSS:如何更改位置:相对于固定和保留;“左”;及;top";价值观_Css_Angular - Fatal编程技术网

CSS:如何更改位置:相对于固定和保留;“左”;及;top";价值观

CSS:如何更改位置:相对于固定和保留;“左”;及;top";价值观,css,angular,Css,Angular,我正在用Angular2写一份草稿。元素使用ng进行排列,默认为位置:相对。要移动元素,我需要将“位置”属性更改为“固定”。这会导致图元位置突然跳变 我如何解决这个问题 模板- <li *ngFor = "#el of dragZoneElems; #idx = index"> <h1 [dragResponder] = "true">{{el.first}} {{el.last}}</h1> </li> 设定位置函数- SetPositio

我正在用Angular2写一份草稿。元素使用ng进行排列,默认为位置:相对。要移动元素,我需要将“位置”属性更改为“固定”。这会导致图元位置突然跳变

我如何解决这个问题

模板-

<li *ngFor = "#el of dragZoneElems; #idx = index">
  <h1 [dragResponder] = "true">{{el.first}} {{el.last}}</h1>
</li>
设定位置函数-

SetPosition(pos : Object){
    this._renderer.setElementStyle(this._elem.nativeElement, "position", "fixed");
    this._renderer.setElementStyle(this._elem.nativeElement, "left", (pos["left"] - this._margin[1]).toString() + "px");
    this._renderer.setElementStyle(this._elem.nativeElement, "top" ,  (pos["top"] - this._margin[0]).toString() + "px");
}

固定位置与窗口位置相关,如果需要保持相同的位置,则必须计算窗口宽度和高度,并根据您的值进行增减。

这个问题最终变得无关紧要。发生跳转是因为我没有在单击时重新初始化边界。

如何获得相对于窗口的初始位置(由ng设置)?是的,窗口、文档和页面有许多属性。查看Hi,我似乎找不到一个属性在位置从相对更改为固定时发生更改。然而,元素仍然会改变位置。我需要知道哪些属性值发生更改,以便可以相应地偏移当前位置。
SetPosition(pos : Object){
    this._renderer.setElementStyle(this._elem.nativeElement, "position", "fixed");
    this._renderer.setElementStyle(this._elem.nativeElement, "left", (pos["left"] - this._margin[1]).toString() + "px");
    this._renderer.setElementStyle(this._elem.nativeElement, "top" ,  (pos["top"] - this._margin[0]).toString() + "px");
}