我有一个html
页面,我想显示两个人之间的聊天内容,聊天框是这样的
<!-- right chat -->
<div class="chat__conversation-board__message-container reversed">
<div class="chat__conversation-board__message__person">
<div class="chat__conversation-board__message__person__avatar">
<img src="./customer.jpg" alt="Dennis Mikle"/>
</div>
<span class="chat__conversation-board__message__person__nickname">Dennis Mikle</span>
</div>
<div class="chat__conversation-board__message__context">
<div class="chat__conversation-board__message__bubble">
<span>some text</span>
</div>
</div>
</div>
<!-- left chat -->
<div class="chat__conversation-board__message-container">
<div class="chat__conversation-board__message__person">
<div class="chat__conversation-board__message__person__avatar">
<img src="./agent.jpg" alt="Monika Figi"/>
</div>
<span class="chat__conversation-board__message__person__nickname">Monika Figi</span>
</div>
<div class="chat__conversation-board__message__context">
<div class="chat__conversation-board__message__bubble">
<span>some text</span>
</div>
</div>
</div>
聊天内容的data.json
是这样的
{
"lyrics": [
{
"line": "line 1 start",
"position": "r",
"time": 4.5
},
{
"line": "answer 1",
"position": "l",
"time": 9.03
},
{
"line": "line 2 start",
"position": "r",
"time": 14.01
}
]
}
我从服务器获取data.json
并将其显示在index.html
上,我希望在正文中创建position
类型为(left=l or right=r)
的元素
1条答案
按热度按时间sz81bmfz1#
下面是我的示例代码,供您参考:
我在容器的类名中添加了"right"和"left"。
因此,我可以根据"position"属性选择适当的容器来存储新内容。