在线演示

demo

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>留言板</title>
  8. <link rel="stylesheet" href="hw.css" />
  9. <link rel="stylesheet" href="static/css/iconfont.css" />
  10. </head>
  11. <body>
  12. <!-- 演示区域 -->
  13. <div class="showArea">
  14. <!-- 在线客服头部 -->
  15. <div class="title">
  16. <button onclick="back()" title="返回">&lt;</button>
  17. <span>在线客服</span>
  18. </div>
  19. <div class="displayArea">
  20. <!-- 1.留言板图标 -->
  21. <!-- 2.图标选中颜色变化 -->
  22. <div class="msgIcon iconfont icon-kefu" onclick="showMsg()"></div>
  23. <!-- 3.设置留言板样式 -->
  24. <div class="msgDisplay">
  25. <!-- 展示客户问题 -->
  26. <div class="msgShow">
  27. <ul class="msgShowList">
  28. </ul>
  29. </div>
  30. <!-- 客户输入文本框 -->
  31. <div class="msgInput">
  32. <textarea
  33. name="inputData"
  34. id="inputData"
  35. onkeydown="submitMsg(this)"
  36. placeholder="请输入,按Enter直接发送消息"
  37. autofocus
  38. ></textarea>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <script>
  44. function showMsg() {
  45. const msgIcon = document.querySelector(".msgIcon");
  46. const title = document.querySelector(".title");
  47. const msgDisplay = document.querySelector(".msgDisplay");
  48. msgIcon.style.display = "none";
  49. title.style.display = "block";
  50. msgDisplay.style.display = "grid";
  51. }
  52. function back() {
  53. const msgIcon = document.querySelector(".msgIcon");
  54. const title = document.querySelector(".title");
  55. const msgDisplay = document.querySelector(".msgDisplay");
  56. title.style.display = "none";
  57. msgDisplay.style.display = "none";
  58. msgIcon.style.display = "block";
  59. }
  60. // 1. 独立完成留言板功能,要求使用CSS进行页面美化
  61. // 2. (选做)将留言板功能升级为自动客服回复(定时器实现)
  62. function submitMsg(ele) {
  63. if (event.key === "Enter") {
  64. // 判断是否输入为空
  65. if (ele.value.trim() !== "") {
  66. const ul = document.querySelector(".msgShowList");
  67. const li = document.createElement("li");
  68. li.innerHTML =
  69. `<p>
  70. <img src="static/img/userProfilePicture.jpeg">` +
  71. `<span>${ele.value.trim()}</span>
  72. </p>`;
  73. ul.insertAdjacentElement("beforeEnd", li);
  74. webpageMsg(ele.value.trim());
  75. } else {
  76. alert("输入有误,请重新输入!");
  77. }
  78. event.preventDefault();
  79. ele.value = "";
  80. ele.focus();
  81. }
  82. }
  83. function webpageMsg(lo) {
  84. const ul = document.querySelector(".msgShowList");
  85. const li = document.createElement("li");
  86. li.innerHTML = `<span>对方正在输入</span>`;
  87. ul.insertAdjacentElement("beforeEnd", li);
  88. setTimeout(function () {
  89. if(lo==="天王盖地虎"){
  90. li.innerHTML = `<p>
  91. <img src="static/img/webProfilePicture.jpg">` +
  92. `<span>小鸡炖蘑菇</span>
  93. </p>`;
  94. li.className="userRight";
  95. ul.replaceChild(li,ul.lastChild);
  96. }else if(lo==="12345"){
  97. li.innerHTML = `<p>
  98. <img src="static/img/webProfilePicture.jpg">` +
  99. `<span>上山打老虎</span>
  100. </p>`;
  101. li.className="userRight";
  102. ul.replaceChild(li,ul.lastChild);
  103. }
  104. else{
  105. li.innerHTML = `<p>
  106. <img src="static/img/webProfilePicture.jpg">` +
  107. `<span>口令不对再想想</span>
  108. </p>`;
  109. li.className="userRight";
  110. ul.replaceChild(li,ul.lastChild);
  111. }
  112. }, 1000);
  113. }
  114. </script>
  115. </body>
  116. </html>
  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a{
  7. text-align: none;
  8. color:black;
  9. }
  10. ul{
  11. list-style-type: none;
  12. }
  13. body{
  14. background-color: azure;
  15. }
  16. .showArea{
  17. width: 601px;
  18. height: 600px;
  19. margin: auto;
  20. display: grid;
  21. grid-template-rows: 40px 1fr;
  22. border-radius: 10px;
  23. background-color: rgb(15, 127, 219);
  24. }
  25. .showArea .title{
  26. width: 601px;
  27. text-align: center;
  28. background-color: rgba(175, 33, 226, 0.661);
  29. padding: 3px;
  30. border-radius: 10px 10px 0 0;
  31. display: none;
  32. }
  33. .showArea .title button{
  34. border-radius: 5px;
  35. outline: none;
  36. border: none;
  37. background-color: white;
  38. color: #BBB;
  39. margin-right: 10px;
  40. padding: 5px;
  41. }
  42. .showArea .title button:hover{
  43. cursor: pointer;
  44. background-color: coral;
  45. color: white;
  46. }
  47. .showArea .title>span{
  48. letter-spacing: 5px;
  49. font-size: 25px;
  50. color:white;
  51. }
  52. .displayArea{
  53. position: relative;
  54. }
  55. .displayArea .msgIcon{
  56. width: 70px;
  57. height: 70px;
  58. background-color: white;
  59. border-radius: 50%;
  60. font-size: 65px;
  61. text-align: center;
  62. color: #e1e1e1;
  63. position: absolute;
  64. margin-top: 300px;
  65. right: 0;
  66. margin-right: 10px;
  67. /* 测试先关闭 */
  68. /* display: none; */
  69. }
  70. .displayArea .msgIcon:hover{
  71. cursor: pointer;
  72. color:coral;
  73. }
  74. .msgDisplay{
  75. border: 0.5px solid black;
  76. border-radius: 0 0 10px 10px;
  77. display: grid;
  78. grid-template-rows: 400px 1fr;
  79. display: none;
  80. }
  81. .msgDisplay .msgShow{
  82. background-color: #fefefe;
  83. }
  84. .msgDisplay .msgInput textarea{
  85. padding: 10px;
  86. outline: none;
  87. border: none;
  88. border-top: 1px solid #eee;
  89. border-radius: 0 0 10px 10px;
  90. resize: none;
  91. width: 600px;
  92. height: 160px;
  93. }
  94. .msgDisplay .msgShow{
  95. padding: 10px;
  96. overflow: auto;
  97. }
  98. .msgDisplay .msgShow img{
  99. width: 50px;
  100. height: 50px;
  101. vertical-align:middle;
  102. border-radius: 10px;
  103. }
  104. .msgDisplay .msgShow ul li{
  105. margin-top: 5px;
  106. }
  107. .msgDisplay .msgShow ul p{
  108. width: 300px;
  109. background-color: #eee;
  110. border-radius: 10px;
  111. }
  112. .msgDisplay .msgShow ul li>span{
  113. display: flex;
  114. place-content: center;
  115. }
  116. .msgDisplay .msgShow .userRight{
  117. display: flex;
  118. place-content: flex-end;
  119. }

更多相关文章

  1. Android(安卓)自定义输入框
  2. Android(安卓)dialog 强制弹出输入法
  3. Android复选框(CheckBox)的现实
  4. PHP的命令行扩展Readline相关函数的使用
  5. Android(安卓)邮箱验证
  6. Android(安卓)模拟MotionEvent事件 触发输入法
  7. Android输入框被键盘遮挡
  8. Android日语输入法Simeji使用示例
  9. Android(安卓)EditText 密码输入框可见性设置

随机推荐

  1. Android引入签名文件
  2. Android(安卓)8.1 来电显示SIM卡
  3. Android:获取APK签名信息
  4. Android studio 3.1.4 无法获取pom文件
  5. Android NDK开发之Android.mk文件
  6. Android(安卓)progressBar代码设置进度条
  7. Android 单独抽取 WebRtc-AGC(音频增益) 模
  8. 【转】Android Makefile中是 如何识别 TA
  9. 安卓开发入门学习笔记
  10. Android知识体系总结之Android部分View绘