Skip to content

Instantly share code, notes, and snippets.

@kotarok
kotarok / observeInView.js
Created August 16, 2025 12:35
Observe elements entering/leaving viewport and apply classes
/**
* Observe elements entering/leaving viewport and apply classes
* @param {string} selector - CSS selector
* @param {Object} [options] - Configuration object
* @param {Element} [options.scope=document] - Element to search within
* @param {Element} [options.root=null] - Root element for intersection (null = viewport)
* @param {string} [options.inView] - Class to add when element enters view
* @param {string} [options.outView] - Class to add when element leaves view (requires toggle: true)
* @param {Function} [options.onEnter] - Callback when element enters view
* @param {Function} [options.onLeave] - Callback when element leaves view
@kotarok
kotarok / animateClass.js
Last active August 16, 2025 09:37
Animate CSS classes with easing and timing control
/**
* Animate CSS classes with easing and timing control
* @param {string} selector - CSS selector
* @param {Object} [options] - Animation options
* @param {number} [options.duration=0] - Total animation duration (ms)
* @param {string} [options.easing='easeOut'] - Easing function: 'linear', 'easeIn', 'easeOut', 'easeInOut'
* @param {boolean} [options.debug=false] - Debug mode
*/
const animateClass = (selector, options = {}) => new ClassAnimator(selector, options)
@kotarok
kotarok / markupText.js
Last active August 16, 2025 06:34
Simple text markup function
/**
* Simple text markup function
* @param {string} selector - CSS selector
* @param {string} chars - Character class pattern
* @param {string|Object|Function} processor - Class name, attributes object, or custom function
*/
const markupText = (selector, chars, processor) => {
const regex = new RegExp(`[${chars}][${chars}\\s]*[${chars}]?`, 'g')
let process
@kotarok
kotarok / kanafn.json
Last active December 6, 2021 09:55
Karabiner setting file for my own key bind modification.
{
"title": "KanaFN (“keyexchange”-compatible)",
"rules": [
{
"description": "KanaFN: japanese_kana to fn unlesss alone",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "japanese_kana",
@kotarok
kotarok / .csscomb.json
Last active March 1, 2018 11:15
My CSS Comb setting
{
"remove-empty-rulesets": true,
"always-semicolon": true,
"color-shorthand": true,
"leading-zero": false,
"unitless-zero": true,
"color-case": "lower",
"element-case": "lower",
"quotes": "single",
"space-before-combinator": " ",
var PositionObserver = function(callback, options) {
this.root = window;
this.rootMargin = this.buildRootMargin_('0');
this.threasholds = undefined;
this.els_ = [];
this.callback_ = callback;
this.init_(options);
this.listen_();
}
@kotarok
kotarok / ripple.scss
Created November 26, 2017 20:50
Material Design ripple effect Sass mixin
@mixin ripple($color: rgba(#fff, .2)) {
position: relative;
overflow: hidden;
&::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 5px;
@kotarok
kotarok / myKeyhacConfig.py
Last active July 13, 2017 05:32
My Keyhac setting
import sys
import os
import datetime
import subprocess
from keyhac import *
def configure(keymap):
@kotarok
kotarok / picoquery.js
Created January 23, 2017 13:06
Array based tiny jQuery subset alternative with minimum number of methods.
var pq = function(q, f) {
return new pq.Obj(q);
};
pq.Obj = function(q) {
if (typeof q === 'string') {
return this.find(q);
} else if (q instanceof pq.Obj) {
return q;
} else if (q instanceof HTMLElement) {
@kotarok
kotarok / nq.js
Last active February 17, 2017 13:31
Array based tiny jQuery subset alternative with minimum number of methods + useful functionalities. Less than 1kb gzipped.
(function(window) {
'use strict';
var camelize = function(str) {
str = str.replace(/^\s+/, '');
return str.replace(/[\W]+([a-z0-9])(\w*)/ig, function(match, p1, p2) {
return p1.toUpperCase() + p2;
});
};