简体   繁体   English

Adobe Animate Javascript-如何使动态文本垂直居中?

[英]Adobe Animate Javascript - How to vertically center dynamic text?

Adobe Animate CC Adobe Animate CC
Javascript Java脚本

Does anyone know how to vertically center text in a dynamic text box in Adobe Animate when using Javascript ? 有谁知道使用Javascript时如何在Adobe Animate的动态文本框中垂直居中放置文本? Not to be confused with vertically centering text in HTML with CSS. 不要与带有CSS的HTML中的垂直居中文本混淆。

This doesn't work: 这不起作用:

myTextBox.style.display="table-cell";
myTextBox.style.verticalAlign="middle";

Assuming that your textbox is on the stage (not embedded in a MovieClip), you can vertically align a textbox by updating its y position. 假设您的文本框位于舞台上(未嵌入在MovieClip中),则可以通过更新其y位置垂直对齐文本框。 To do so, you must get a reference to the stage's height and divide this value by 2. 为此,您必须参考载物台的高度并将该值除以2。

For example: 例如:

this.stop();

this.myTextBox.y = (stage.canvas.height) / 2;

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

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