Catch Me If You Can
How do I make an catch me if you can?
Do try. It is possible to click. It's just meant to be hard. If you're on a trackpad.... Good luck tee, eh, eh, eh.. What is a catch me if you can? How do you make a catch me if you can? This script and codes were developed by Pedro Tavares on 01 December 2022, Thursday.
Catch Me If You Can - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Catch Me If You Can</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel='stylesheet prefetch' href='css/rwxpbb.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <p id="text">Click Me</p>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Catch Me If You Can - Script Codes CSS Codes
/* **************************************** */
/* Default CSS styles being imported from:
/* https://codepen.io/dipscom/pen/RWXPBB
/* **************************************** */
/* ****************** */
/* Notes and reminders
/* ****************** */
/* ****************** */
/* Local CSS styling
/* ****************** */
body { overflow: hidden;
}
.container { width: 200px; min-width: 0px; text-align: center; border: 6px solid $textColor; border-radius: 12px; position: absolute; left: 50%; top: 50%; // transform: translate(-50%, -50%); margin: 0;
}
.container { cursor: pointer;
}
p { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
}
Catch Me If You Can - Script Codes JS Codes
var btn = document.querySelector('div');
var txt = document.querySelector('p');
var fun = true;
TweenMax.set(btn, {x:0, y:0, xPercent:-50, yPercent:-50})
window.addEventListener('mousemove', trackMouse);
btn.addEventListener('mouseenter', onMouseEnter);
btn.addEventListener('mouseleave', onMouseLeave);
btn.addEventListener('mousedown', onMouseDown);
btn.addEventListener('mouseup', onMouseUp);
btn.addEventListener('touchend', onTouch);
function onTouch() { // thisis acomm btn.removeEventListener('mousemove', trackMouse); btn.removeEventListener('mouseenter', onMouseEnter); btn.removeEventListener('mouseleave', onMouseLeave); btn.removeEventListener('mouseup', onMouseUp); txt.innerHTML = "Greasy fingers are not allowed. Use a mouse." TweenMax.delayedCall(3, function() { txt.innerHTML = "Click Me"; btn.addEventListener('mousemove', trackMouse); btn.addEventListener('mouseenter', onMouseEnter); btn.addEventListener('mouseleave', onMouseLeave); btn.addEventListener('mouseup', onMouseUp); });
}
function onMouseUp() { btn.removeEventListener('mouseup', onMouseUp); btn.style.cursor = 'auto'; txt.innerHTML = "Damn..." TweenMax.to(btn, 0.3, {scale:1, ease:Back.easeOut.config(5)}); TweenMax.delayedCall( 2, function() { TweenMax.to(btn, 3, {x:0, y:0, ease:Power1.easeInOut}); txt.innerHTML = "Fun's over. Go home."; btn.addEventListener('mouseenter', onMouseEnter); btn.addEventListener('mouseleave', onMouseLeave); })
}
function onMouseDown() { if( isTouchDevice() ) return; txt.innerHTML = "Ouch!" btn.removeEventListener('mouseenter', onMouseEnter); btn.removeEventListener('mouseleave', onMouseLeave); btn.removeEventListener('mousedown', onMouseDown); fun = false; TweenMax.killTweensOf(btn); TweenMax.to(btn, 0.8, {scale:0.9, ease:Elastic.easeOut.config(1)}); window.removeEventListener('mousemove', trackMouse);
}
function onMouseEnter() { if( fun ) { txt.innerHTML = "NOOOOOOOO!" } else { txt.innerHTML = "Not playing anymore... :(" }
}
function onMouseLeave() { if( fun ) { txt.innerHTML = "Click Me" } else { txt.innerHTML = "Fun's over. Go home."; }
}
function trackMouse(e) { if( isTouchDevice() ) return; var mouseX = event.clientX; // Get the horizontal coordinate var mouseY = event.clientY; // Get the vertical coordinate var btnX = btn.getBoundingClientRect().left + ( (btn.getBoundingClientRect().right - btn.getBoundingClientRect().left) / 2 ); var btnY = btn.getBoundingClientRect().top + ( (btn.getBoundingClientRect().bottom - btn.getBoundingClientRect().top) / 2 ); var distX = btnX - mouseX; var distY = btnY - mouseY; // The closer the mouse is, the more the button moves var toMoveX = ( 1 / (distX) * 50000 ); var toMoveY = (1 / (distY) * 50000 ); var midX = window.innerWidth * 0.5; var midY = window.innerHeight * 0.5; var dur = Math.abs( ( toMoveX + toMoveY ) * 0.01 ); moveBox(dur, toMoveX, toMoveY) // console.log("MousX:", btnX, " midX:", "dur", dur); oldBtnX = btnX; oldBtnY = btnY;
}
function moveBox(dur, toMoveX, toMoveY) { TweenMax.to(btn, dur, {x:toMoveX, y:toMoveY, ease:Power4.easeOut})
}
function isTouchDevice() { return 'ontouchstart' in document.documentElement;
}
Developer | Pedro Tavares |
Username | dipscom |
Uploaded | December 01, 2022 |
Rating | 4 |
Size | 4,094 Kb |
Views | 8,096 |
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 |
GSAP - Animate SVG path with AttrPlugin | 2,074 Kb |
GSAP - Responsive Corner Navigation | 3,210 Kb |
Using Functions to Build a timeline - Broken | 1,831 Kb |
SVGText - Pattern Fill | 20,155 Kb |
Animated SVG Blur | 2,288 Kb |
Buttons.js - Example | 3,730 Kb |
Mask Within Mask | 3,843 Kb |
GSAP - Fun with Cycle and Bezier | 3,862 Kb |
Shooting Hoops | 6,731 Kb |
SVG Grid Mask | 3,267 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 |
CSS3 Media Queries demo | Machal | 1,824 Kb |
My Starter Kit For Codepen | Dkdesign | 2,012 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 Kb |
Fading gradient button | Insprd | 1,713 Kb |
STIKHOI | Denmch | 7,122 Kb |
Clock with full screen background | Owebboy | 2,415 Kb |
Heatmap Color Scales | Stevepepple | 2,331 Kb |
Css or Czz.. | Judag | 4,111 Kb |
Midterm dry run | Jds317 | 1,649 Kb |
Underlined form fields | Mitchdot | 2,323 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!