Skip to content

Instantly share code, notes, and snippets.

View kahl-dev's full-sized avatar
🏠
Working from home

Patrick Kahl kahl-dev

🏠
Working from home
View GitHub Profile
@kahl-dev
kahl-dev / smoothscroll.es6.js
Last active March 18, 2020 15:49
smoothscroll.es6.js
/**
* Smooth Scroll Script
* URL: https://gist.github.com/patrickkahl/641f0b5c80d3fbdf174dac4ee8d60fb1
*
* POLYFILLS:
* - https://github.com/iamdustan/smoothscroll
* - https://github.com/w3c/IntersectionObserver/tree/master/polyfill
*/
import 'intersection-observer'
import 'core-js/features/promise'
@kahl-dev
kahl-dev / sample.js
Last active May 28, 2019 11:29
Remove all ascii control characters, including CR and LF, from string
myString.replace(/[^\x20-\x7E]/gmi, "")
<template>
<button
:class="{'c-btn--text': text}"
class="c-btn"
@click="$emit('click')"
>
<slot />
</button>
</template>
@kahl-dev
kahl-dev / onVisibilityChange.es6.js
Created September 8, 2017 18:01
ES6 event for changing state of is in viewport or not
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
const viewPortHeight =
window.innerHeight || document.documentElement.clientHeight;
const topBottom =
(rect.top > 0 && rect.top < viewPortHeight) ||
(rect.bottom > 0 && rect.bottom < viewPortHeight) ||
(rect.top <= 0 && rect.height + rect.top >= viewPortHeight);
// @TODO LeftRight
@kahl-dev
kahl-dev / throttle.es6.js
Created September 8, 2017 17:31
ES6 Throttle
function throttle(fn, threshhold = 250, scope, args = []) {
let last, deferTimer;
return function() {
const context = scope || this;
const now = +new Date();
const eventArgs = arguments;
if (last && now < last + threshhold) {
// hold on to it
clearTimeout(deferTimer);
@kahl-dev
kahl-dev / dataset.es6.js
Created September 8, 2017 11:47
Handle dataset
function hyphenToCamelCase(string) {
return string.replace('data-', '').replace(/-([a-z])/g, string => {
return string[1].toUpperCase();
});
}
function camelCaseToHyphen(string) {
return `data-${string.replace(/([A-Z])/g, string => {
return `-${string.toLowerCase()}`;
})}`;
@kahl-dev
kahl-dev / onScrollOnce.es6.js
Last active September 8, 2017 17:49
ES6 event to trigger once per scroll
function onScrollOnce(fn, scope) {
let mw1 = 0,
mw2 = 0;
let lock;
return function() {
const context = scope || this;
const args = arguments;
const e = args[0];
const d = e.deltaY;