Skip to content

Instantly share code, notes, and snippets.

View hoyangtsai's full-sized avatar
⌨️
Prompting

Hoyang Tsai hoyangtsai

⌨️
Prompting
View GitHub Profile
@hoyangtsai
hoyangtsai / scrollToEl.js
Created August 18, 2020 09:36 — forked from benhatsor/scrollToEl.js
Smooth scroll to element - Pure JS
function scrollToEl(el) {
var rect = el.getBoundingClientRect(),
scrollTop = window.pageYOffset || document.documentElement.scrollTop,
scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
elTop = rect.top + scrollTop,
elLeft = rect.left + scrollLeft;
window.scrollTo({
top: elTop,
left: elLeft,
@hoyangtsai
hoyangtsai / utils.numberToDay.js
Last active March 27, 2022 09:47 — forked from niksumeiko/utils.numberToDay.js
#JavaScript function that converts a number into the #2-digits day of the month with leading zeros (01-31)
/**
* Turns a number/string to 2 digits day of the month with leading zero.
* @param {number|string} day to turn into day.
* @return {string}
*/
function numberToDay(j) {
return ('0' + j).slice(-2);
}
// Examples: