Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > แจก Code สร้าง Web Click Counter แบบแยกระหว่าง Single Click / Double Click / Triple Click ได้ และเป็น Responsive Website ครับ



 

แจก Code สร้าง Web Click Counter แบบแยกระหว่าง Single Click / Double Click / Triple Click ได้ และเป็น Responsive Website ครับ

 



Topic : 137013



โพสกระทู้ ( 131 )
บทความ ( 12 )



สถานะออฟไลน์




แจก Code สร้าง Web Click Counter แบบแยกระหว่าง Single Click / Double Click / Triple Click ได้ และเป็น Responsive Website ครับ

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Click Counter Website</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      text-align: center;
      background-color: #ffffff;
    }
    
    div {
      font-size: 48px;
      margin: 20px;
      border: 1px solid #000000;
      padding: 10px;
      background-color: #cccccc;
    }
    
    span {
      display: inline-block;
      margin: 10px;
      padding: 10px;
      width: 100px;
      height: 30px;
      font-size: 20px;
      text-align: center;
      border: 1px solid #000000;
      background-color: #eeeeee;
      color: #000;
      font-weight: bold;
    }
    
    button {
      font-size: 24px;
      padding: 10px;
      border: 1px solid #000000;
      background-color: #0000ff;
      color: #ffffff;
    }
    
    @media (max-width: 768px) {
      button {
        width: 50%;
      }
      span {
        width: 50%;
      }
    }
    
    @media (max-width: 480px) {
      button {
        width: 70%;
      }
      span {
        width: 70%;
      }
    }
  </style>
</head>
<body>
  <div id="count">0</div>
  <span id="single">Single: 0</span>
  <span id="double">Double: 0</span>
  <span id="triple">Triple: 0</span><br><br>
  <button id="click">Click Me</button>
  <script>
    // Get the div and span elements from the HTML document
    const div = document.getElementById("count");
    const single = document.getElementById("single");
    const double = document.getElementById("double");
    const triple = document.getElementById("triple");
    
    // Get the button element from the HTML document
    const button = document.getElementById("click");
    
    // Initialize the click counts and the timestamps of the last three clicks
    let totalCount = 0;
    let singleCount = 0;
    let doubleCount = 0;
    let tripleCount = 0;
    let lastClick = 0;
    let secondLastClick = 0;
    let thirdLastClick = 0;
    
    // Define the maximum time interval between two clicks in milliseconds
    const maxInterval = 300;
    
    // Add an event listener to the button element that will execute a function on every click
    button.addEventListener("click", function() {
      // Increment the total click count by one and update the div element
      totalCount++;
      div.textContent = totalCount;
    
      // Shift the timestamps of the last three clicks by one position and assign the current timestamp to the last position
      thirdLastClick = secondLastClick;
      secondLastClick = lastClick;
      lastClick = Date.now();
    
      // Compare the timestamps of the last three clicks and determine if they are within the maximum time interval
      if (lastClick - secondLastClick <= maxInterval && secondLastClick - thirdLastClick <= maxInterval) {
        // If yes, increment the triple click count by one and update the span element
        tripleCount++;
        triple.textContent = "Triple: " + tripleCount;
      } else if (lastClick - secondLastClick <= maxInterval) {
        // If yes, increment the double click count by one and update the span element
        doubleCount++;
        double.textContent = "Double: " + doubleCount;
      } else {
        // If no, increment the single click count by one and update the span element
        singleCount++;
        single.textContent = "Single: " + singleCount;
      }
    });
  </script>
</body>
</html>




Tag : PHP, HTML, CSS, HTML5







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2023-05-08 15:33:49 By : doanga2007 View : 300 Reply : 0
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : แจก Code สร้าง Web Click Counter แบบแยกระหว่าง Single Click / Double Click / Triple Click ได้ และเป็น Responsive Website ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่