Skip to content

Instantly share code, notes, and snippets.

@celsowhite
celsowhite / scroll-direction-indicator.js
Created November 30, 2020 13:27
Detect scroll direction using gsap.
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
function initScrollDirectionIndicator() {
// GSAP Plugins
gsap.registerPlugin(ScrollTrigger);
/*----------------------------
Elements
----------------------------*/
@celsowhite
celsowhite / flickityInit.js
Last active October 21, 2020 13:58
Init helper for Flickity instances.
import Flickity from 'flickity-fade';
require('flickity-imagesloaded');
/**
* Init Flickity
*
* @param node container - The container element node. Flickity gallery and arrows should be within this container.
* @param object flickityOptions - The specific flickity api options for this initialization.
*
* output Sets up a Flickity slider instance with standard slider customizations done via the api.
@celsowhite
celsowhite / target-blank.js
Last active October 13, 2020 19:40
Link external links to a new window.
/*-------------------------
Target Blank
---
Link all external links to a new window.
-------------------------*/
document.addEventListener('DOMContentLoaded', () => {
for (var c = document.getElementsByTagName('a'), a = 0; a < c.length; a++) {
var b = c[a];
b.getAttribute('href') &&
@celsowhite
celsowhite / section-checker.js
Created May 28, 2020 19:27
Check section visibility as a user scrolls.
/*-----------------------
Offset
---
Get the offset of an element on the page relative to the document.
-----------------------*/
function offset(el) {
const rect = el.getBoundingClientRect(),
scrollTop = window.pageYOffset || document.documentElement.scrollTop;
return { top: rect.top + scrollTop, bottom: rect.bottom + scrollTop };
@celsowhite
celsowhite / acf-local-fields-to-json.php
Created May 22, 2020 14:13
Convert ACF Fields Registered via PHP to JSON
<?php
/*-----------------------------
Notes
- After running the script then remove the "ID" and "_valid" keys from all fields in the json output. These are extraneous and may cause import errors.
Resource - https://dev-notes.eu/2017/01/convert-acf-fields-registered-by-php-to-importable-json-format/
-----------------------------*/
$groups = acf_get_local_field_groups();
.underline-text {
display: inline-block;
position: relative;
text-decoration: none;
/* This is the key. The lines that this border applies to must be 'inline'. */
display: inline;
background-image: linear-gradient(to bottom, transparent 20%, #00e692 21%);
/* This ensures the line appears at the right vertical position on each line. 1em will correspond exactly to the height of the font. */
background-position: 0 1em;
background-repeat: no-repeat;
@celsowhite
celsowhite / proportional_div.html
Last active January 22, 2019 20:58
Example of a proportionally sized div. Div automatically keeps proportions regardless of container width.
<div class="product_card">
<div class="product_image" style="background-image: url('https://celsowhite.com/static/img/about/me.jpg')">
<!-- Important: Any content in this proportional div must be positioned absolute so it adapts to the container proportions. -->
</div>
<div class="product_info">
<h2>Celso</h2>
</div>
</div>
@celsowhite
celsowhite / rewrites.htaccess
Last active August 17, 2018 14:02
Common rewrites I use in projects.
# Force all www to redirect to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
# Force all http to redirect to https
RewriteEngine On
RewriteCond %{HTTPS} off
@celsowhite
celsowhite / plain_list_sort.js
Created July 10, 2018 22:36
Plain List Sort
// Sort a plain list of names alphabetically.
const people = `
Mike Dobbs
Peace Walker
Adam Vinson
`;
// Convert the list to an array. Splitting on the new line.
@celsowhite
celsowhite / git_tips.md
Last active February 6, 2019 22:20
Helpful Git Tips

Checkout New Branch from previous commit

git checkout -b branchname <sha1-of-commit or HEAD~3>

Rename Remote URL

Mainly used if a remote repository name has changed.

git remote set-url origin {new-url}