สร้างปุ่ม CHAT สำหรับเว็บไซต์

 




ตัวอย่าง


CODE : index.html

<!DOCTYPE html>

<html lang="th">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Chat Popup</title>
  <style>

    @import url('https://fonts.googleapis.com/css2?family=K2D&family=Kanit&display=swap');

    /* ปุ่มหลัก */
    #main-button {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      background-image: url('https://semicon.github.io/img/logo2.png'); /* ใส่ URL รูปภาพของปุ่ม */
      background-size: cover;
      position: fixed;
      right: 20px;
      bottom: 20px;
      z-index: 1000;
      cursor: pointer;
      box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.2);
      display: flex;
      align-items: center;
      justify-content: center;
    }

    /* ป๊อปอัพ */
    #chat-popup {
      max-width: 350px;
      background-color: #FAFAFA;
      position: fixed;
      right: 20px;
      bottom: 100px;
      z-index: 999;
      border-radius: 15px;
      box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
      display: none;
      flex-direction: column;
      overflow: hidden;
      border: 1px solid #ccc;
      padding-bottom: 20px;
      font-family: "K2D", sans-serif;
    }

    /* ส่วนหัวของป๊อปอัพ */
    #chat-popup-header {
      background-color: #FA7268;
      padding: 10px;
      color: white;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    /* ข้อความส่วนหัวพร้อมโลโก้ */
    #chat-popup-header img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      margin-right: 10px;
    }

    #chat-popup-header p {
      margin: 0;
    }

    /* เนื้อหาภายในป๊อปอัพ */
    #chat-popup-content {
      padding: 15px;
      display: flex;
      flex-direction: column;
      position: relative;
      margin-top: 10px;
    }

    /* ข้อความ */
    #chat-popup-content p {
      border: 1px solid #0084FF;
      border-radius: 0px 10px 10px 10px;
      background-color: #E6F4FF;
      padding: 15px;
      margin: 0;
      font-size: 14px;
      color: #333;
      margin-left: 40px; /* เว้นที่สำหรับไอคอน */
    }

    /* ไอคอนในกล่องข้อความ */
    #chat-popup-content img {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      position: absolute;
      top: 15px;
      left: 10px;
    }

    /* ส่วนด้านล่างป๊อปอัพ */
    #chat-popup-footer {
      padding: 10px;
      display: flex;
      justify-content: center;
      gap: 10px;
    }

    .chat-popup-footer{
      padding: 10px;
      text-align: center;
      justify-content: center;
    }

    /* สไตล์ปุ่มแชท */
    .chat-button {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }

    #line-button {
      background-color: #00B900;
    }

    #messenger-button {
      background-color: #0084FF;
    }

    h3{
      margin: 0;
    }

    .close-btn{
      font-size: 2.5rem;
      cursor: pointer;
    }
  </style>
</head>
<body>

  <!-- ปุ่มหลัก -->
  <div id="main-button">
    <!-- โลโก้ปุ่มหลัก -->
    <img src="https://semicon.github.io/img/logo2.png" alt="Profile" style="border-radius: 50%; width: 60px; height: 60px;">
  </div>

  <!-- ป๊อปอัพ -->
  <div id="chat-popup">
    <div id="chat-popup-header">
      <div style="display: flex; align-items: center;">
        <!-- โลโก้ส่วนหัวด้านบน -->
        <img src="https://semicon.github.io/img/logo2.png" alt="Logo">
        <div>
          <h3>Guru Chian</h3>
          <p>Typically replies instantly</p>
        </div>
      </div>
      <div class="close-btn" onclick="togglePopup()">&times;</div>
    </div>
    <div id="chat-popup-content">
      <!-- โลโก้ขนาดเล็กหน้ากล่องข้อความ -->
      <img src="https://semicon.github.io/img/logo2.png" alt="Logo">
      <!-- กล่องข้อความต้อนรับ -->
      <p>Hello! 😀<br> How may we help you?<br> Just send us a message now to get assistance.</p>
    </div>
    <div class="chat-popup-footer">
      <h3>Start Chat with:</h3>
    </div>
    <div id="chat-popup-footer">
      <div id="line-button" class="chat-button" onclick="openLine()">
        <img src="https://cdn-icons-png.flaticon.com/128/3670/3670089.png" alt="Line" width="50px" height="50px">
      </div>
      <div id="messenger-button" class="chat-button" onclick="openMessenger()">
        <img src="https://cdn-icons-png.flaticon.com/128/3670/3670042.png" alt="Messenger" width="50px" height="50px">
      </div>
      <div id="facebook-button" class="chat-button" onclick="openFacebook()">
        <img src="https://cdn-icons-png.flaticon.com/128/3670/3670032.png" alt="facebook" width="50px" height="50px">
      </div>
    </div>
  </div>

  <script>
    function togglePopup() {
      const popup = document.getElementById('chat-popup');
      popup.style.display = (popup.style.display === 'none' || popup.style.display === '') ? 'block' : 'none';
    }

    // แสดงป๊อปอัพเมื่อคลิกปุ่มหลัก
    document.getElementById('main-button').addEventListener('click', togglePopup);

    function openLine() {
      const lineId = "xxxxxxxx"; // xxxxxxxx ใส่ Line ID ของคุณ
      const url = "https://line.me/ti/p/" + lineId;
      window.open(url, "_blank");
    }

    function openMessenger() {
      const messengerId = "xxxxxxxx"; // xxxxxxxx ใส่ Facebook Messenger ID ของคุณ
      const url = "https://www.messenger.com/t/" + messengerId;
      window.open(url, "_blank");
    }

    function openFacebook() {
      const facebookId = "xxxxxxxxx"; // xxxxxxxx ใส่ Facebook ID ของคุณ
      const url = "https://www.facebook.com/" + facebookId;
      window.open(url, "_blank");
    }
  </script>

</body>
</html>




แสดงความคิดเห็น (0)
ใหม่กว่า เก่ากว่า