Skip to content

Instantly share code, notes, and snippets.

@jeangontijo
jeangontijo / toggle_class_on_click.js
Created September 2, 2020 23:12
Toggle Class on Click
function toggleClass(element, oldClass, newClass) {
let e = document.querySelector(element).classList;
if(e.contains(oldClass)){
e.replace(oldClass, newClass);
}else{
e.replace(newClass, oldClass);
}
}
button.addEventListener('click', () => {
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
@jeangontijo
jeangontijo / svg_path_length.js
Created February 6, 2020 19:26
Check SVG path length
console.log(Math.ceil(document.querySelector("path").getTotalLength()));
@jeangontijo
jeangontijo / custom_underline.css
Created February 6, 2020 19:22
Custom Underline
a {
box-shadow: inset 0 -0.2em white, inset 0 -0.25em blue;
text-decoration: none;
}
@jeangontijo
jeangontijo / scrollanimation.js
Created January 14, 2020 20:56
Keyframe Animation to Scroll
:root * {
/* Pause the animation */
animation-play-state: paused;
/* Bind the animation to scroll */
animation-delay: calc(var(--scroll) * -1s);
/* These last 2 properites clean up overshoot weirdness */
animation-iteration-count: 1;
animation-fill-mode: both;
}
@jeangontijo
jeangontijo / followmouse.js
Created October 28, 2019 13:19
Follow Mouse (Translate and Rotate)
var el = document.querySelector(".element");
var elX = el.getBoundingClientRect().x + el.offsetWidth / 2;
var elY = el.getBoundingClientRect().y + el.offsetHeight / 2;
function followMouse(e) {
var moveX = e.clientX - elX;
var moveY = e.clientY - elY;
var radians = Math.atan2(moveY, moveX);
var degrees = (radians * (180 / Math.PI));
requestAnimationFrame(update.bind(update,moveX, moveY, degrees));
@jeangontijo
jeangontijo / microjquery.js
Last active August 9, 2019 21:26
Micro JQuery
function $(e){
let el = document.querySelectorAll(e.toString());
if (el.length > 1) {
return el;
} else {
return document.querySelector(e.toString());
}
}
$('#element').classList.add('active');
@jeangontijo
jeangontijo / prevent_safari_ios_bounce.css
Last active January 20, 2019 22:50
Prevent Safari iOS Bounce
body {
position: fixed;
overflow: hidden;
}
// That's it ! Tested in iOS 12
@jeangontijo
jeangontijo / svgmorph.html
Created January 18, 2019 19:20
SVG Morph Animation
<svg class="blob" viewBox="0 0 1000 1000" xmlns="http://www.w3.org/2000/svg">
<path d="pathA" fill-rule="nonzero">
<animate dur="5s" repeatCount="indefinite" attributeName="d" values="pathA;pathB;pathA" fill="freeze"
calcMode="spline"
keySplines="0.4 0 0.2 1; 0.4 0 0.2 1">
</path>
</svg>
@jeangontijo
jeangontijo / fade.css
Created November 12, 2018 16:09
Fade animation on scroll
.element {
opacity: 1;
transform: translate3d(0, 0, 0);
}
.fade {
opacity: 0;
transform: translate3d(0, 3rem, 0);
transition-property: opacity, transform;
transition-duration: 0.8s, 1.4s;
transition-timing-function: linear, cubic-bezier(0.175, 0.885, 0.32, 1.275);