下面这一行有些不对劲。我的高度和宽度正确显示在我的应用程序中。如果我包括+ character.offsetX + 'px' + character.offsetY + 'px'
则不会出现背景图像样式。
Character.offsetX 和 offsetY 是从字符对象提供的硬编码数字。
我在网上找到的示例非常简单,并没有显示如何进行background-image
的速记版本来设置background-position
<li *ngFor="let character of this.characterList" [ngStyle]= "{'height':'50px', 'width':'50px', 'background-image':'url(' + character.fullImagePath + ')' + character.offsetX + 'px' + character.offsetY + 'px' }"
background-image
不允许设置其他background-*
属性 - 您需要为此使用background
速记:
<li *ngFor="let character of this.characterList" [ngStyle]= "{'height':'50px', 'width':'50px', 'background':'url(' + character.fullImagePath + ') ' + character.offsetX + 'px ' + character.offsetY + 'px' }"