大气好看的在线联系客服代码(html+js+css)

这是一个在线联系客服功能的页面,展示了在线客服联系方式和留言表单切换功能。用户可以通过填写姓名、联系方式、邮箱账号和备注信息来提交留言。同时,在提交前需要输入正确的验证码进行验证。留言内容可以通过第三方AnPush推送到QQ、邮箱、微信等平台。页面布局简洁清晰,卡片式展示在线留言和联系方式,整体设计美观大方。通过这个功能,用户可以方便地与客服进行沟通和留言交流。
摘要由智能技术生成

做一个在线联系客服功能,页面展示了在线客服联系方式,也同时可以切换在线表单留言,但是留言不会记录,会通过第三方,AnPush可以推送到qq,邮箱,微信里面,需要自信配置key,当然了,可以改为本地php存储入库,看需求吧

如图所示:

微信截图_20240416161936.png

微信图片_20240416162325.png

这是代码html

  1. <section id="ns-contact-us" class="kf_contact">
  2. <a class="ns-btn ns-btn-primary" href="javascript:void(0);">联系我们</a>
  3. <ul class="ns-float-details">
  4. <li>
  5. <h2>联系我们</h2>
  6. <div class="ns-close-float-contact-us">
  7. <span></span>
  8. <span></span>
  9. </div>
  10. </li>
  11. <li>
  12. <div class="hz_kf_box nosee bs" id="ly_box">
  13. <ul class="ly_con">
  14. <li class="tellz"><strong class="ts"><i class="txt">在线留言</i></strong></li>
  15. <li><input type="text" class="sign__input" name="name" placeholder="姓名" required=""></li>
  16. <li><input type="text" class="sign__input" name="tell" placeholder="联系方式" required=""></li>
  17. <li><input type="text" class="sign__input" name="mail" placeholder="邮箱账号" required=""></li>
  18. <li><textarea name="contents" placeholder="备注信息" rows="2"></textarea></li>
  19. <li>
  20. <div class="capt">
  21. <div id="captcha" class="captcha"></div>
  22. <div class="capinput"><input type="text" id="answer" name="capt" placeholder="输入验证码"></div>
  23. </div>
  24. </li>
  25. <li><button class="submit-btn ly_btnn" type="submit" name="mtn" disabled><span>提交</span></button>
  26. </li>
  27. </ul>
  28. </div>
  29. <div class="hz_kf_box seek" id="tel_box">
  30. <ul class="kf_contactList kf1-flex bs s-box1">
  31. <li class="hz_kf_l1">
  32. <strong class="ts"><i class="txt">售前咨询</i></strong>
  33. </li>
  34. <li>
  35. <p>售前咨询热线</p>
  36. <a href="tel:xxx">
  37. <p>xxxx</p>
  38. </a>
  39. </li>
  40. <li>
  41. <p>售前咨询电话</p>
  42. <a href="tel:xxx">
  43. <p>xxxx</p>
  44. </a>
  45. </li>
  46. <li class="hz_kf_l2">
  47. <div class="ly_btn" id="ly_btn">
  48. <span>提交需求 ></span>
  49. </div>
  50. </li>
  51. </ul>
  52. <ul class="kf_contactList kf2-flex bs s-box2">
  53. <i class="bg-pri"></i>
  54. <div class="wx_pic">
  55. <img src="https://www.uicreater.com/home/images/footer/QR.png">
  56. <span>微信联系</span>
  57. </div>
  58. <li class="hz_kf_l1">
  59. <strong class="ts"><i class="txt">售后咨询</i></strong>
  60. </li>
  61. <li>
  62. <p>售后服务热线</p>
  63. <a href="tel:xxx">
  64. <p>xxxx</p>
  65. </a>
  66. </li>
  67. <li>
  68. <p>售后服务热线</p>
  69. <a href="tel:xxxx">
  70. <p>xxxx</p>
  71. </a>
  72. </li>
  73. <li>
  74. <p>
  75. 媒体邮箱
  76. </p>
  77. <a href="mail:sales@wintoptec.com">
  78. <p>sales@wintoptec.com</p>
  79. </a>
  80. </li>
  81. </ul>
  82. </div>
  83. </li>
  84. <li>
  85. </li>
  86. <li class="tellz">
  87. <div class="hz_kf_box hz_kf_box2 arr_btn nosee bs">
  88. 返回电话联系
  89. </div>
  90. <div class="tell_btn">
  91. <div class="hz_kf_box hz_kf_box2 bs">
  92. <a href="">
  93. <span>人工在线咨询</span></a>
  94. </div>
  95. </div>
  96. </li>
  97. <li>
  98. <div class="hz_kf_box hz_kf_box3">让科技服务日常,探索美好生活的无限可能</div>
  99. </li>
  100. </ul>
  101. </section>

这是jquery部分

  1. <script>
  2. $(document).ready(function() {
  3. generateCaptcha();
  4. initializeEventHandlers();
  5. });
  6. function generateCaptcha() {
  7. var num1 = Math.floor(Math.random() * 10);
  8. var num2 = Math.floor(Math.random() * 10);
  9. var result = num1 + num2;
  10. $('#captcha').text(num1 + ' + ' + num2 + ' = ?');
  11. $('#captcha').data('result', result);
  12. }
  13. function validateEmail(email) {
  14. var re = /^([a-zA-Z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
  15. return re.test(email);
  16. }
  17. function initializeEventHandlers() {
  18. $(".ns-btn-primary").on("click", function() {
  19. $("#ns-contact-us").addClass("active");
  20. });
  21. $(".ns-close-float-contact-us").on("click", function() {
  22. $("#ns-contact-us").removeClass("active");
  23. $(".arr_btn").addClass("nosee");
  24. $(".tell_btn").removeClass("nosee");
  25. $("#ly_box").addClass("nosee");
  26. $("#tel_box").removeClass("nosee");
  27. });
  28. $("#ly_btn").on("click", function() {
  29. $("#tel_box").addClass("nosee");
  30. $("#ly_box").removeClass("nosee");
  31. $(".tell_btn").addClass("nosee");
  32. $(".arr_btn").removeClass("nosee");
  33. })
  34. $(".arr_btn").on("click", function() {
  35. $(".arr_btn").addClass("nosee");
  36. $(".tell_btn").removeClass("nosee");
  37. $("#ly_box").addClass("nosee");
  38. $("#tel_box").removeClass("nosee");
  39. })
  40. $('#answer').on('blur', function() {
  41. $('#answer').next('.error-msg').remove();
  42. $('#answer').next('.ok-msg').remove();
  43. var answer = parseInt($(this).val(), 10);
  44. var correctAnswer = parseInt($('#captcha').data('result'), 10);
  45. if (answer === correctAnswer) {
  46. $('#captcha').next('.error-msg').remove();
  47. $('<span class="ok-msg">验证成功</span>').insertAfter('#answer');
  48. $('.ly_btnn').removeAttr('disabled');
  49. } else {
  50. if ($('#captcha').next('.error-msg').length === 0) {
  51. $('<span class="error-msg">验证失败,请重新输入</span>').insertAfter('#answer');
  52. $('.ly_btnn').prop('disabled', true);
  53. }
  54. }
  55. });
  56. $(".submit-btn").click(function() {
  57. var name = $("input[name='name']").val();
  58. var tell = $("input[name='tell']").val();
  59. var mail = $("input[name='mail']").val();
  60. var content = $("textarea[name='contents']").val();
  61. if (name.trim() === '' || tell.trim() === '' || content.trim() === '') {
  62. alert("请填写所有必填字段!");
  63. } else if (!validateEmail(mail)) {
  64. alert("请提供一个有效的邮箱地址!");
  65. } else {
  66. var text = '姓名:'+name+', 电话:'+tell+', 邮箱:'+mail+', 备注信息:'+content;
  67. var settings = {
  68. "url": "apikey",
  69. "method": "POST",
  70. "timeout": 0,
  71. "headers": {
  72. "Content-Type": "application/x-www-form-urlencoded"
  73. },
  74. "data": {
  75. "title": '新留言线索',
  76. "content": text,
  77. "channel": xxxx
  78. }
  79. };
  80. $.ajax(settings).done(function(response) {
  81. console.log(response);
  82. alert('发布成功');
  83. $("input[name='name']").val('');
  84. $("input[name='tell']").val('');
  85. $("input[name='mail']").val('');
  86. $("textarea[name='contents']").val('');
  87. }).fail(function(jqXHR, textStatus, errorThrown) {
  88. console.log("Request failed: " + textStatus);
  89. });
  90. }
  91. });
  92. }
  93. </script>

剩下是css部分,就可以了

  1. <style>
  2. .bg-pri {
  3. content: " ";
  4. position: absolute;
  5. border-radius: 50%;
  6. background: #fc625d !important;
  7. width: 12px;
  8. height: 12px;
  9. box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
  10. float: right;
  11. right: 60px;
  12. top: 16px
  13. }
  14. .capt {
  15. display: flex;
  16. flex-wrap: wrap;
  17. }
  18. .capt .captcha {
  19. line-height: 37px;
  20. flex: 0 0 auto;
  21. width: 20%;
  22. }
  23. .capt .capinput {
  24. flex: 0 0 auto;
  25. width: 80%;
  26. display: flex;
  27. flex-wrap: wrap;
  28. }
  29. #answer {
  30. max-width: 200px;
  31. }
  32. .ok-msg {
  33. color: #30bf50;
  34. font-size: 12px;
  35. line-height: 37px;
  36. margin-left: 20px;
  37. }
  38. .error-msg {
  39. color: red;
  40. font-size: 12px;
  41. line-height: 37px;
  42. margin-left: 20px;
  43. }
  44. .ts {
  45. position: relative;
  46. }
  47. .ts .txt {
  48. font-style: normal;
  49. position: relative;
  50. }
  51. .ts::before {
  52. content: '';
  53. display: block;
  54. position: absolute;
  55. left: 0;
  56. right: 0;
  57. bottom: 0;
  58. top: 60%;
  59. background-color: rgba(255, 255, 0, 0.7);
  60. }
  61. .ly_box2 {
  62. margin-top: 0 !important;
  63. background-color: #fff;
  64. border-radius: 8px;
  65. padding: 0;
  66. justify-content: center !important;
  67. align-items: center;
  68. font-size: 15px;
  69. font-weight: bold;
  70. }
  71. .bs {
  72. box-shadow: 0 0 13px 0 rgb(82 63 105 / 5%);
  73. }
  74. .kf_contact a:hover {
  75. color: #0d6efd;
  76. }
  77. .nosee {
  78. display: none !important;
  79. }
  80. .ly_con {
  81. width: 100%;
  82. background-color: #fff;
  83. border-radius: 8px;
  84. padding: 10px 0;
  85. box-sizing: border-box;
  86. }
  87. .ly_con>li {
  88. padding: 8px 25px;
  89. }
  90. .ly_con input,
  91. .ly_con textarea {
  92. width: 100%;
  93. padding: 5px 16px;
  94. font-size: 13px;
  95. color: #9199a1;
  96. border-radius: inherit;
  97. background: #eff6ff;
  98. border: 0px;
  99. }
  100. .ly_con textarea{
  101. height:100px;
  102. }
  103. .ly_btnn {
  104. width: 82px;
  105. background-color: #0d6efd;
  106. color: #fff;
  107. border: none;
  108. font-size: 13px;
  109. border-radius: 4px;
  110. letter-spacing: 5px;
  111. display: block;
  112. padding: 6px 20px;
  113. }
  114. .ly_btnn:disabled {
  115. pointer-events: none;
  116. color: #ffffff;
  117. background-color: #9aa5af;
  118. border-color: #9aa5af;
  119. cursor: not-allowed;
  120. }
  121. .arr_btn {
  122. cursor: pointer;
  123. }
  124. .ly_btn {
  125. cursor: pointer;
  126. }
  127. #ns-contact-us {
  128. position: fixed;
  129. bottom: 30px;
  130. right: 30px;
  131. z-index: 9999;
  132. }
  133. #ns-contact-us.kf_contact {
  134. bottom: 130px;
  135. }
  136. #ns-contact-us.kf_contact.active {
  137. top: 50%;
  138. bottom: auto;
  139. left: 50%;
  140. right: auto;
  141. transform: translate(-50%, -50%);
  142. box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
  143. border-radius: 12px;
  144. overflow: hidden;
  145. }
  146. a.ns-btn.ns-btn-primary {
  147. background: #0d6efd;
  148. color: white;
  149. }
  150. a.ns-btn {
  151. padding: 10px 18px;
  152. font-size: 13px;
  153. border-radius: 6px;
  154. }
  155. .ns-float-details {
  156. background: url(https://www.uicreater.com/home/images/footer/bg.png) top right no-repeat #fcfcfc;
  157. background-size: cover;
  158. }
  159. .kf_contact .ns-float-details {
  160. width: 606px;
  161. }
  162. #ns-contact-us.kf_contact .ns-float-details {
  163. background-color: #f6f8fa;
  164. }
  165. #ns-contact-us.kf_contact .ns-float-details li h2 {
  166. font-size: 22px;
  167. background-image: url(https://www.wintoptec.com/syd/images/asnbg.jpg);
  168. background-repeat: no-repeat;
  169. background-size: cover;
  170. background-position: center center;
  171. }
  172. .hz_kf_box {
  173. width: 90.3%;
  174. margin: 5% auto 0;
  175. display: flex;
  176. flex-direction: row;
  177. justify-content: space-between;
  178. /*align-items: center;*/
  179. }
  180. .hz_kf_box2 {
  181. margin-top: 2%;
  182. background-color: #fff;
  183. border-radius: 8px;
  184. padding: 15px 0;
  185. justify-content: center;
  186. align-items: center;
  187. font-size: 14px;
  188. color: #e60012;
  189. font-weight: bold;
  190. }
  191. .hz_kf_box2 a{
  192. color: #e60012;
  193. }
  194. .hz_kf_box3 {
  195. margin-top: 3%;
  196. font-size: 12px;
  197. color: #999999;
  198. display: block;
  199. line-height: 1;
  200. }
  201. .wx_pic {
  202. position: absolute;
  203. bottom: 123px;
  204. right: 20px;
  205. width: 100px;
  206. height: 30px;
  207. z-index: 8040;
  208. border-radius: 50%;
  209. box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.1);
  210. cursor: pointer;
  211. text-align: center;
  212. }
  213. .wx_pic img {
  214. width: 100%
  215. }
  216. .wx_pic span {
  217. font-size: 12px;
  218. }
  219. .kf_contactList {
  220. background-color: #fff;
  221. border-radius: 8px;
  222. padding: 15px 0;
  223. box-sizing: border-box;
  224. }
  225. .kf1-flex {
  226. width: 38%;
  227. }
  228. .kf2-flex {
  229. width: 60%;
  230. position: relative;
  231. }
  232. .kf_contactList>li {
  233. padding: 0 30px 15px;
  234. }
  235. .kf_contactList>li {
  236. font-size: 18px;
  237. color: #333;
  238. }
  239. .hz_kf_l1 {
  240. padding-bottom: 20px;
  241. font-weight: bold;
  242. }
  243. .hz_kf_l2 {
  244. margin: 5px 0;
  245. }
  246. .kf_contactList>li span {
  247. font-size: 14px;
  248. color: #e60012;
  249. font-weight: bold;
  250. }
  251. .kf_contactIcon1 {
  252. width: 22px;
  253. margin-right: 7px;
  254. margin-top: -6px;
  255. }
  256. .s-box1 {
  257. background: linear-gradient(180deg, #fffaf0 0%, #ffffff 100%);
  258. }
  259. .s-box2 {
  260. background: linear-gradient(180deg, #fff8f8 0%, #ffffff 100%);
  261. }
  262. .s-box3 {
  263. background: linear-gradient(180deg, #f0f6ff 0%, #ffffff 100%);
  264. }
  265. #ns-contact-us.kf_contact .ns-float-details li::after {
  266. display: none;
  267. }
  268. #ns-contact-us.kf_contact .kf_contactList>li p {
  269. padding: 0;
  270. font-size: 14px;
  271. }
  272. #ns-contact-us.kf_contact .kf_contactList>li p:first-child {
  273. font-size: 14px;
  274. }
  275. #ns-contact-us.kf_contact .ns-float-details li p:last-child {
  276. padding-bottom: 0;
  277. }
  278. .kf_contactImg1 {
  279. width: 6px;
  280. }
  281. .kf_contactImg2 {
  282. width: 18px;
  283. }
  284. .kf_contactIcon6 {
  285. width: 7px;
  286. }
  287. .hz_kf_l2:hover .kf_contactImg1 {
  288. transform: translate(3px, 0);
  289. }
  290. @media screen and (max-width:768px) {
  291. .kf_contact { display: none;}
  292. #ns-contact-us.kf_contact {
  293. bottom: 100px;
  294. }
  295. #ns-contact-us.kf_contact .ns-btn {
  296. font-size: 4.3vw;
  297. padding: 6px 25px;
  298. }
  299. .kf_contact .ns-float-details {
  300. width: 93.3vw;
  301. margin: 0 auto;
  302. }
  303. #ns-contact-us.kf_contact .ns-float-details li h2 {
  304. font-size: 4.5vw;
  305. }
  306. .kf_contactList {
  307. /*padding:15px 15px 0 15px;*/
  308. }
  309. .kf_contactList>li {
  310. margin-bottom: 3%;
  311. padding: 5% 15px;
  312. }
  313. .kf_contactList>li {
  314. font-size: 3.7vw;
  315. }
  316. .kf_contactIcon1 {
  317. width: 4.6vw;
  318. }
  319. .kf_contactList>li span {
  320. font-size: 3.5vw;
  321. }
  322. .hz_kf_l1 {
  323. padding-bottom: 7%;
  324. }
  325. .hz_kf_l2 {
  326. /*padding:3% 0 5%;*/
  327. margin: 0 auto;
  328. }
  329. #ns-contact-us.kf_contact .kf_contactList>li p:first-child {
  330. font-size: 2.9vw;
  331. }
  332. #ns-contact-us .ns-float-details li p:last-child {
  333. font-size: 4.5vw;
  334. white-space: pre-wrap;
  335. }
  336. .hz_kf_box2 {
  337. font-size: 3.7vw;
  338. }
  339. .hz_kf_box3 {
  340. font-size: 3.5vw;
  341. }
  342. .kf_contactList>li:hover {
  343. background-color: #FFF;
  344. }
  345. .hz_kf_box2:hover {
  346. background-color: #FFF;
  347. }
  348. }
  349. #ns-contact-us .ns-btn {
  350. margin: 0
  351. }
  352. #ns-contact-us.active .ns-float-details {
  353. display: block;
  354. padding-bottom: 20px
  355. }
  356. #ns-contact-us.active .ns-btn {
  357. display: none;
  358. }
  359. #ns-contact-us .ns-float-details {
  360. display: none;
  361. box-shadow: 0 2px 4px rgba(0, 0, 0, .1)
  362. }
  363. #ns-contact-us .ns-float-details li {
  364. position: relative;
  365. list-style-type: none;
  366. }
  367. #ns-contact-us .ns-float-details li:last-child:after {
  368. display: none
  369. }
  370. #ns-contact-us .ns-float-details li::after {
  371. content: "";
  372. display: block;
  373. height: 1px;
  374. width: calc(100% - 60px);
  375. margin: 0 auto;
  376. background: #e5e5e5
  377. }
  378. #ns-contact-us .ns-float-details li h2 {
  379. color: #fff;
  380. padding: 20px 30px;
  381. background: #0d6efd;
  382. font-size: 24px
  383. }
  384. #ns-contact-us .ns-float-details li a:hover {
  385. text-decoration: none
  386. }
  387. #ns-contact-us .ns-float-details li h3 {
  388. padding: 20px 30px;
  389. font-size: 18px;
  390. transition: all .5s;
  391. display: block;
  392. color: #000;
  393. position: relative
  394. }
  395. #ns-contact-us .ns-float-details li h3:hover {
  396. background: #f5f5f5
  397. }
  398. #ns-contact-us .ns-float-details li h3::after {
  399. content: "";
  400. background-size: cover;
  401. background-position: -6px 0;
  402. width: 6px;
  403. height: 10px;
  404. position: absolute;
  405. top: 50%;
  406. right: 30px;
  407. transform: translateY(-50%)
  408. }
  409. #ns-contact-us .ns-float-details li p {
  410. padding: 5px 30px;
  411. font-size: 16px;
  412. display: flex;
  413. align-items: center;
  414. }
  415. #ns-contact-us .ns-float-details li p:last-child {
  416. padding-bottom: 15px
  417. }
  418. #ns-contact-us .ns-float-details li p img {
  419. margin-right: 10px
  420. }
  421. #ns-contact-us .ns-float-details li .ns-close-float-contact-us span {
  422. width: 20px;
  423. height: 3px;
  424. position: absolute;
  425. top: 50%;
  426. right: 30px;
  427. background: #fff;
  428. cursor: pointer
  429. }
  430. #ns-contact-us .ns-float-details li .ns-close-float-contact-us span:nth-of-type(1) {
  431. transform: translateY(-50%) rotate(45deg)
  432. }
  433. #ns-contact-us .ns-float-details li .ns-close-float-contact-us span:nth-of-type(2) {
  434. transform: translateY(-50%) rotate(-45deg)
  435. }
  436. </style>
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/2257
0 评论
1k

发表评论

!