简体   繁体   English

如何在角度5中以编程方式转换html元素

[英]how to transform html element programmatically in angular 5

I am trying to transform the html element programmatically. 我正在尝试以编程方式转换html元素。 Updated transform value changed in console-tab but not changed in element-tab in the browser. 更新的转换值在控制台选项卡中已更改,但在浏览器的元素选项卡中未更改。

onDragStart(element: HTMLElement) {
    this.elementRef = element;
    var style = window.getComputedStyle(element);
    var matrix = new WebKitCSSMatrix(style.webkitTransform);
    this.translateY = matrix.m42;
    console.log(this.translateY) //outputs: 85, because its current Y-location is 85px 

    element.style.transform = "translate( 0px," + this.translateY + "px)";
    console.log(element);    
  }

where I am wrong? 我哪里错了? I am facing this issue about last 24 hours. 我大约在过去24小时内面临此问题。

syntactically and logically the question was correct. 从句法和逻辑上讲,这个问题是正确的。

Actually I have not set the top -attribute of the html-element that's why it was behaving non-ideally (going at location translation(0px,0px) from its current location) on first click. 实际上,我还没有设置html元素的top属性,这就是为什么它在第一次单击时表现不理想的原因(从当前位置到位置translation(0px,0px))。

First set top , then transform it anywhere because setting top sustains its first position and then you may translate it somewhere 首先设置top ,然后transformtransform到任何位置,因为top保持其第一位置,然后您可以将其转换到某个位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM