Jquery Extension to Handle Clicks and Double Clicks
How do I make an jquery extension to handle clicks and double clicks?
This Jquery extension allows you to handle single and double clicks on the same element correctly.. What is a jquery extension to handle clicks and double clicks? How do you make a jquery extension to handle clicks and double clicks? This script and codes were developed by Alex Vazquez on 10 September 2022, Saturday.
Jquery Extension to Handle Clicks and Double Clicks - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Jquery Extension to Handle Clicks and Double Clicks</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>JQuery Handle Single & Double Clicks on Same Element</h1>
<br />
<h1 id="clickme">CLICK ME ONCE OR TWICE</h1>
<h1 id="result">Result of Click1</h1> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Jquery Extension to Handle Clicks and Double Clicks - Script Codes CSS Codes
@import url(https://fonts.googleapis.com/css?family=Bevan);
body { font-family: 'Bevan', cursive; background-color: #eddfed; margin: 50px;
}
h1 { padding: 25px; background-color: #d7dadb; text-align: center; border: 1px solid grey;
}
Jquery Extension to Handle Clicks and Double Clicks - Script Codes JS Codes
$.fn.singleAndDouble = function(singleClickFunc, doubleClickFunc) { // This means it'll take a minimum of 200ms to take the single // click action. If it's too short the single and double actions // will be called. // The default time between clicks on windows is 500ms (http://en.wikipedia.org/wiki/Double-click) // Adjust accordingly. var timeOut = 200; var timeoutID = 0; var ignoreSingleClicks = false; this.on('click', function(event) { if (!ignoreSingleClicks) { // The double click generates two single click events // and then a double click event so we always clear // the last timeoutID clearTimeout(timeoutID); timeoutID = setTimeout(function() { singleClickFunc(event); }, timeOut); } }); this.on('dblclick', function(event) { clearTimeout(timeoutID); ignoreSingleClicks = true; setTimeout(function() { ignoreSingleClicks = false; }, timeOut); doubleClickFunc(event); });
};
var singleClickCalled = false;
$('#clickme').singleAndDouble( function(event) { singleClickCalled = true; $('#result').html('Single Click Captured'); setTimeout(function() { singleClickCalled = false; }, 300); }, function(event) { if (singleClickCalled) { // This is actually an error state // it should never happen. The timeout would need // to be adjusted because it may be too close $('#result').html('Single & Double Click Captured'); } else { $('#result').html('Double Click Captured'); } singleClickCalled = false; }
);
Developer | Alex Vazquez |
Username | quezo |
Uploaded | September 10, 2022 |
Rating | 3.5 |
Size | 2,407 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Default DC.js Template | 1,705 Kb |
A Pen by Alex Vazquez | 2,280 Kb |
A Pen by Alex Vazquez | 1,670 Kb |
Maximized TextArea | 2,295 Kb |
A Wufoo Form | 8,735 Kb |
DC.js Example Pie Chart | 2,016 Kb |
Simple Redux, React Example | 2,538 Kb |
Redux Template | 1,245 Kb |
Code Pen Link Generator | 3,477 Kb |
Event Bus Example using JQuery. | 1,951 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Calendar | Miroot | 2,033 Kb |
Arrow Navigation | Hinducows | 1,973 Kb |
Experiments with Vertical Centering | KatieK2 | 3,924 Kb |
Cars going | Netoguimaraes | 1,699 Kb |
Weather App | Kw7oe | 3,162 Kb |
PNotify Demo | Adittmar | 1,731 Kb |
Responsive scrolling text | Ashdurham | 2,259 Kb |
Ipad Mini Showcase | Hornebom | 10,479 Kb |
Day 1 - Portfolio | Chpecson | 3,532 Kb |
Vertically rotating text with CSS | Nopr | 2,141 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!