你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
发现
话题
全文搜索
登录
[]HTMLDivElement 怎么设置图片和文本底对齐 或 居中对齐
没有找到相关结果
已邀请:
与内容相关的链接
提交
2 个回复
ymsdandan
赞同来自:
您可以先看下这个
http://layaair.ldc.layabox.com ... BHTML
唐皆
赞同来自:
可以修改Laya的Layout类:
函数_multiLineLayout
```
//生成排版的行
for (i = 0; i < n; i++) {
oneLayout = elements[i];
if (oneLayout == null) {
if (!tLineFirstKey) {
x += Layout.DIV_ELEMENT_PADDING;
}
curLine.wordStartIndex = curLine.elements.length;
continue;
}
tLineFirstKey = false;
if (oneLayout instanceof IHtml.HTMLBrElement) {
addLine();
curLine.y = y;
curLine.h = lineHeight;
continue;
} else if (oneLayout._isChar()) {
htmlWord = <HTMLChar>oneLayout;
w = htmlWord.width + htmlWord.style.letterSpacing; // 下面要用到w,所以先计算(Bug:英文的宽度按照前面的汉字的宽度计算导致错误换行)
h = htmlWord.height;
if (!htmlWord.isWord) //如果是完整单词
{
if (lines.length > 0 && (x + w) > width && curLine.wordStartIndex > 0) //如果完整单词超界,需要单词开始折到下一行
{
var tLineWord: number = 0;
tLineWord = curLine.elements.length - curLine.wordStartIndex + 1;
curLine.elements.length = curLine.wordStartIndex;
i -= tLineWord;
addLine();
continue;
}
newLine = false;
tWordWidth += htmlWord.width;
} else {
newLine = nextNewline || (htmlWord.char === '\n');
curLine.wordStartIndex = curLine.elements.length;
}
nextNewline = false;
newLine = newLine || ((x + w) > width);
newLine && addLine();
curLine.minTextHeight = Math.min(curLine.minTextHeight, oneLayout.height);
} else {
curStyle = oneLayout._getCSSStyle();
sprite = (<HTMLElement>oneLayout);
curPadding = curStyle.padding;
//curStyle._getCssFloat() === 0 || (endAdjust = true);
newLine = nextNewline || curStyle.getLineElement();
w = sprite.width + curPadding[1] + curPadding[3] + curStyle.letterSpacing;
h = sprite.height + curPadding[0] + curPadding[2];
nextNewline = curStyle.getLineElement();
newLine = newLine || ((x + w) > width && curStyle.wordWrap);
newLine && addLine();
}
curLine.elements.push(oneLayout);
curLine.h = Math.max(curLine.h, h);//计算最大宽和高
oneLayout.x = x;
/////------------------------------------------------------
///此处的xxx是个自定义变量,用于偏移Y坐标使用,例如:可以设置图片往上偏移a,这样图片就可以居中显示了
///`<img width='40' height='40' sy='a' src='url'></img>`
oneLayout.y = y + Number(oneLayout["
sy
"] || 0);
////--------------------------------------------------
x += w;
curLine.w = x - letterSpacing;
curLine.y = y;
maxWidth = Math.max(x + exWidth, maxWidth);
}
```
要回复问题请先
登录
发起人
swp_laya
相关问题
请问LayaAir中如何使图片以圆形的方式显示?
文本如何自动换行
matter中layasprite怎么改变图片大小?
关于文本遮挡
ios14系统下 blendMode='lighter' 图片异常
分享,扩展Laya.Text组件实现简单的富文本
Texture图片能否进行翻转?
btn 鼠标移动上去默认文本颜色是绿色,我想换成其他颜色,如何操作?
如何设置Sprite的宽高和点击区域?
Laya native1.0.7, 引擎1.7.14beta,多行文本不换行
Laya使用fairygui的富文本xml解析报错
问题状态
最新活动:
2022-08-11 16:23
浏览:
3071
关注:
3
人
商务合作
2 个回复
ymsdandan
赞同来自:
唐皆
赞同来自:
函数_multiLineLayout
```
//生成排版的行
for (i = 0; i < n; i++) {
oneLayout = elements[i];
if (oneLayout == null) {
if (!tLineFirstKey) {
x += Layout.DIV_ELEMENT_PADDING;
}
curLine.wordStartIndex = curLine.elements.length;
continue;
}
tLineFirstKey = false;
if (oneLayout instanceof IHtml.HTMLBrElement) {
addLine();
curLine.y = y;
curLine.h = lineHeight;
continue;
} else if (oneLayout._isChar()) {
htmlWord = <HTMLChar>oneLayout;
w = htmlWord.width + htmlWord.style.letterSpacing; // 下面要用到w,所以先计算(Bug:英文的宽度按照前面的汉字的宽度计算导致错误换行)
h = htmlWord.height;
if (!htmlWord.isWord) //如果是完整单词
{
if (lines.length > 0 && (x + w) > width && curLine.wordStartIndex > 0) //如果完整单词超界,需要单词开始折到下一行
{
var tLineWord: number = 0;
tLineWord = curLine.elements.length - curLine.wordStartIndex + 1;
curLine.elements.length = curLine.wordStartIndex;
i -= tLineWord;
addLine();
continue;
}
newLine = false;
tWordWidth += htmlWord.width;
} else {
newLine = nextNewline || (htmlWord.char === '\n');
curLine.wordStartIndex = curLine.elements.length;
}
nextNewline = false;
newLine = newLine || ((x + w) > width);
newLine && addLine();
curLine.minTextHeight = Math.min(curLine.minTextHeight, oneLayout.height);
} else {
curStyle = oneLayout._getCSSStyle();
sprite = (<HTMLElement>oneLayout);
curPadding = curStyle.padding;
//curStyle._getCssFloat() === 0 || (endAdjust = true);
newLine = nextNewline || curStyle.getLineElement();
w = sprite.width + curPadding[1] + curPadding[3] + curStyle.letterSpacing;
h = sprite.height + curPadding[0] + curPadding[2];
nextNewline = curStyle.getLineElement();
newLine = newLine || ((x + w) > width && curStyle.wordWrap);
newLine && addLine();
}
curLine.elements.push(oneLayout);
curLine.h = Math.max(curLine.h, h);//计算最大宽和高
oneLayout.x = x;
/////------------------------------------------------------
///此处的xxx是个自定义变量,用于偏移Y坐标使用,例如:可以设置图片往上偏移a,这样图片就可以居中显示了
///`<img width='40' height='40' sy='a' src='url'></img>`
oneLayout.y = y + Number(oneLayout["sy"] || 0);
////--------------------------------------------------
x += w;
curLine.w = x - letterSpacing;
curLine.y = y;
maxWidth = Math.max(x + exWidth, maxWidth);
}
```