Skip to content

Instantly share code, notes, and snippets.

View yhk1038's full-sized avatar

Y. Fred Kim yhk1038

  • @gomicorporation
  • Seoul, Republic of Korea
View GitHub Profile
@yhk1038
yhk1038 / scrollTopArrivedAt.js
Created November 24, 2018 22:03
Execute When the scroll arrived specific offset position from the window's bottom.
/*
* scrollTopArrivedAt.js
* @description
* It's a *boilerplate function* that enable to execute your function when
* the scroll position arrived specific offset from the window's bottom.
* Also, It supports lockable options to avoid duplicate calls due to
* unnecessary scrolling changes.
*
* - bottomOffset: number | optional | (px) default: 0
* - func: function | required | (Your Awesome Function) default: <If it doesn't exist, return false>
@njvack
njvack / README.md
Last active February 8, 2024 21:43
Color to hex and rgba converter

Simple canvas-based color converter

To answer this StackOverflow question I wrote this — a small solution based on a never-rendered <canvas> element. It fills a 1-pixel canvas with the provided fill-style, and then reads the RGBA values of that pixel. It will work with any CSS color -- name, rgba(), hex, or even something more exotic like a gradient or pattern. Invalid colors are always returned as transparent black. Transparent colors are treated as painted on a newly-cleared canvas.

It's been tested in modern-ish versions of IE, Chrome, Safari, and Firefox. The API is:

color_convert.to_hex(color)   # Converts color to a hex-based RGB triple; to_hex('red') returns '#ff0000'
color_convert.to_rgba(color)  # Converts color to an rgba() string; to_rgba('red') returns 'rgba(255,0,0,1)'