Slow Click Button

Developer
Size
3,035 Kb
Views
149,776

How do I make an slow click button?

Sometimes you need a button to take a second before it kicks in. Like say a self-destruct button or something.. What is a slow click button? How do you make a slow click button? This script and codes were developed by Matthew Chase on 25 July 2022, Monday.

Slow Click Button Previews

Slow Click Button - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Slow Click Button</title> <link rel='stylesheet prefetch' href='http://elrumordelaluz.github.io/csshake/css/csshake.min.css'>
<link rel='stylesheet prefetch' href='http://fonts.googleapis.com/css?family=Audiowide'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="button-wrapper"> <button class="slow-click shake-constant">Self Destruct</button>
</div>
<p class="thanks"> Shake CSS effect from <a href="http://elrumordelaluz.github.io/csshake/" target="_blank">http://elrumordelaluz.github.io/csshake/</a>
</p> <script src="js/index.js"></script>
</body>
</html>

Slow Click Button - Script Codes CSS Codes

html { box-sizing: border-box;
}
*, *:before, *:after { box-sizing: inherit;
}
body{ background-color: #202; text-align: center; padding-top: 40px;
}
.thanks{ color: white; font-family: sans-serif; font-size: 11px; margin: 2em 0;
}
.thanks a{ color: yellow;
}
.button-wrapper{ transition: all 0.25s ease; display: inline-block; padding: 20px; background-image: linear-gradient(135deg, yellow 0, yellow 10%, #101 10%, #101 20%, yellow 20%, yellow 30%, #101 30%, #101 40%, yellow 40%, yellow 50%, #101 50%, #101 60%, yellow 60%, yellow 70%, #101 70%, #101 80%, yellow 80%, yellow 90%, #101 90%, #101 100%); border: 3px solid #101; border-radius: 20px; box-shadow: 0 0 20px 6px rgba(255, 0, 0, 0.25);
}
button.slow-click{ font-family: Audiowide; color: #900; background-color: black; border: 2px solid red; font-size: 20px; display: inline-block; padding: 0.3333em 1em; font-size: 200%; position: relative; outline: none; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; user-select: none; font-weight: bold; border-radius: 15px; text-transform: uppercase; box-shadow: inset 0 0 8px 8px rgba(255, 255, 128, 0.1);
}

Slow Click Button - Script Codes JS Codes

(function(){ var button, clickTimeout, frameInterval, holdTime; var clickDuration = 5000; var clickStart = null; function onDocumentReady(){ button = document.querySelector('.slow-click'); button.addEventListener('click', onButtonClick); button.addEventListener('click', onButtonSlowClick); button.addEventListener('mousedown', onMouseDown); button.addEventListener('mouseup', onMouseUp); button.addEventListener('mouseleave', onMouseLeave); } function onMouseLeave(e){ cancelSlowClick(e); } function onMouseUp(e){ cancelSlowClick(e); } function onMouseDown(e){ beginSlowClick(e); } function beginSlowClick(e){ clickStart = Date.now(); clearTimeout(clickTimeout); clickTimeout = setTimeout(function(){ completeSlowClick(e); }, clickDuration); clearInterval(frameInterval); frameInterval = setInterval(function(){ continueSlowClick(e); }, 1000 / 60); } function continueSlowClick(e){ var timeElapsed = Date.now() - clickStart; var interval = timeElapsed / clickDuration; var percentage = (interval * 100).toFixed(4) + '%'; var gradient = [ 'rgba(255, 0, 0, 0.25)', 'rgba(255, 0, 0, 0.25) ' + percentage, 'transparent ' + percentage, ]; var shakeClass = ""; if(interval > 0.05){ shakeClass = "shake shake-little"; } if(interval > 0.33){ shakeClass = "shake"; } if(interval > 0.75){ shakeClass = "shake shake-hard"; } e.target.className = "slow-click shake-constant " + shakeClass; e.target.style.backgroundImage = 'linear-gradient(to right, '+gradient.join(', ')+' )'; } function completeSlowClick(e){ continueSlowClick(e); var click = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true }); click.slowClick = true; e.target.dispatchEvent(click); finishSlowClick(e); } function cancelSlowClick(e){ finishSlowClick(e); } function finishSlowClick(e){ e.target.style.background = null; e.target.className = "slow-click shake-constant"; clearTimeout(clickTimeout); clearInterval(frameInterval); } function onButtonClick(e){ if(e.slowClick !== true){ e.preventDefault(); e.stopImmediatePropagation(); return false; } } function onButtonSlowClick(e){ window.location.href = 'http://i.imgur.com/RTf93hM.gif'; } document.addEventListener('DOMContentLoaded', onDocumentReady);
})();
Slow Click Button - Script Codes
Slow Click Button - Script Codes
Home Page Home
Developer Matthew Chase
Username antishow
Uploaded July 25, 2022
Rating 3.5
Size 3,035 Kb
Views 149,776
Do you need developer help for Slow Click Button?

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!

Matthew Chase (antishow) Script Codes
Create amazing SEO content with AI!

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!