AI聊天-如何让我们的消息框悬浮在固定位置 第3集

本文详细介绍了如何在Vue项目中创建一个可悬浮在屏幕特定位置的聊天发送消息框,包括组件设计、样式调整和代码实现步骤。
摘要由CSDN通过智能技术生成

如何让我们的消息框悬浮在固定位置 第3集

一、前言

上编已为大家介绍了如何画出类似微信一样的聊天记录
本编将为将为大家介绍 如何让我们的消息框如何悬浮在固定位

二、源码地址

本编的学习源码地址已经为大家准备好:从零开始搭建AI聊天

三、效果截图

在这里插入图片描述

四、实现思路

1、新建 组件chat-send组件

2、将发送消息框的样式迁移至chat-send组件

3、设置消息框的input框

4、设置css样式

五、代码讲解

1、chat-send组件的实现

<template>
  <div class="chat-send">
    <div style="display: flex;justify-content: center;align-content: center;align-items: center">
    <input type="textarea" v-model="textarea" class="send-input" placeholder="  请输入您的问题 按 enter 即发送" />
      <span>
        <img src="./../asserts/image/send.png" width="48" height="48">
      </span>
    </div>
  </div>
</template>

<script>
export default {
name: "chat-send",
  data(){
  return{
    textarea:"",
  }
  },
}
</script>

<style scoped>

.chat-send{
  text-align: center;
  border-radius: 10px;
  left: 56%;
  top: 92%;
  position: absolute;
  transform: translate(-50%,-50%);
}
.chat-send input{
  height: 6vh;
  width: 40vw;
  border-radius: 10px;
  background: rgba(254,255,253,0.5)
}
.chat-send button{
  height: 3vh;
  width: 3vw;
  border-radius: 10px;
}
</style>

2、主界面的发送消息框变更为 chat-send

<template>
  <div class="container">
    <div class="aside">
      <div class="logo">logo区域</div>
      <div>聊天选择区域</div>
    </div>
    <div class="main-right">
      <div class="header">标题区域</div>
      <chat-main></chat-main>
      <chat-send></chat-send>
    </div>
  </div>
</template>

<script>
import {setDeviceInfo} from "@/utils/storage";
import ChatMain from "@/components/chat-main";
import ChatSend from "@/components/chat-send";
export default {
name: "index",
  components: {ChatSend, ChatMain},
  data(){
  return{
    deviceType:1, //1pc 2h5
  }
  },
  mounted() {
    this.clientWidth()
  },
  methods:{
    clientWidth(){
      //监听宽度,判断是否关闭对应的菜单
      let deviceInfo = 'pc';
      this.deviceType = 1
      if(document.body.clientWidth>document.body.clientHeight){
        setDeviceInfo(deviceInfo);
      }else{
        deviceInfo = 'h5'
        this.deviceType = 2
        setDeviceInfo(deviceInfo);
      }
    },
  },


}
</script>

<style scoped>
.container{
  text-align: center;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.aside{
  width: 13vw;
  height: calc(100vh);
  background: #f1f0f0;
}
.logo{
  width: 13vw;
  height: 12vh;
}
.main-right{
  width: 87vw;
  height: calc(100vh);
}
.header{
  width: 100%;
  height:7vh;
  background: white;
}


</style>

六、重难度讲解

1、注意在迁移主界面的发送消息框区域内容的过程中,需要做到对应的样式进行迁移

2、迁移的发送消息框组件 chat-send 需要设置position: absolute;根据个人的界面情况设置left 和top 距离

.chat-send{
  text-align: center;
  border-radius: 10px;
  left: 56%;
  top: 92%;
  position: absolute;
  transform: translate(-50%,-50%);
}

3、根据界面样式判断是否需要设置发送消息框的不透明度 rgba(254,255,253,0.5)

.chat-send input{
  height: 6vh;
  width: 40vw;
  border-radius: 10px;
  background: rgba(254,255,253,0.5)
}

七、下一集预告

下一集将会为大家讲解 如何让我们的消息发送给机器人
本编将到这里,如果个人的分享,大佬有什么更优的办法实现,欢迎提出来,最后帮忙关注并点赞哦,
还没下载源码的请前往从零开始搭建AI聊天

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值