Skip to content

Instantly share code, notes, and snippets.

View tak-dcxi's full-sized avatar
🏠
Working from home

TAK tak-dcxi

🏠
Working from home
View GitHub Profile
@tak-dcxi
tak-dcxi / clamp.css
Last active May 30, 2024 10:24
clamp.css
:is(body, body *),
:is(body, body *)::before,
:is(body, body *)::after {
--clamp-root-font-size: 16;
--clamp-slope: calc((var(--clamp-max) - var(--clamp-min)) / (var(--clamp-viewport-max) - var(--clamp-viewport-min)));
--clamp-y-axis-intersection: calc(var(--clamp-min) - (var(--clamp-slope) * var(--clamp-viewport-min)));
--clamp-preffered-value: calc(
var(--clamp-y-axis-intersection) * (1rem / var(--clamp-root-font-size)) + (var(--clamp-slope) * 100vi)
);
--clamp: clamp(
@tak-dcxi
tak-dcxi / backfaceFixed.ts
Created April 30, 2024 15:06
initializeModal
const backfaceFixed = (fixed: boolean): void => {
const scrollBarWidth = getScrollBarSize()
const scrollPosition = getScrollPosition(fixed)
document.body.style.borderInlineEnd = fixed ? `${scrollBarWidth}px solid transparent` : ''
applyStyles(scrollPosition, fixed)
if (!fixed) restorePosition(scrollPosition)
}
const isWritingModeVertical = (): boolean => {
@tak-dcxi
tak-dcxi / backfaceFixed.ts
Last active April 30, 2024 14:43
backfaceFixed
const backfaceFixed = (fixed: boolean): void => {
const scrollBarWidth = getScrollBarSize()
const scrollPosition = getScrollPosition(fixed)
document.body.style.borderInlineEnd = fixed ? `${scrollBarWidth}px solid transparent` : ''
applyStyles(scrollPosition, fixed)
if (!fixed) restorePosition(scrollPosition)
}
const isWritingModeVertical = (): boolean => {
@tak-dcxi
tak-dcxi / initializeAccordion.ts
Last active May 7, 2024 02:17
initializeAccordion
export type AccordionOptions = {
buttonSelector: string | undefined
panelSelector: string | undefined
duration?: number
easing?: string
printAll?: boolean
}
const defaultOptions: AccordionOptions = {
buttonSelector: undefined,
@tak-dcxi
tak-dcxi / initializeDetailsAccordion.ts
Last active April 30, 2024 08:43
initializeDetailsAccordion
export type AccordionOptions = {
duration?: number
easing?: string
printAll?: boolean
}
const defaultOptions: AccordionOptions = {
duration: 300,
easing: 'ease-in-out',
printAll: false,
@tak-dcxi
tak-dcxi / initializeAnchorPositioning.ts
Last active April 28, 2024 12:57
initializeAnchorPositioning
const initializeAnchorPositioning = (): void => {
const anchorElements = document.querySelectorAll('[data-anchor]') as NodeListOf<HTMLElement>
anchorElements.forEach((anchorElement) => {
const targetId = anchorElement.getAttribute('data-anchor')
if (!targetId) return
const anchorTarget = document.getElementById(targetId) as HTMLElement
if (!anchorTarget) return
@tak-dcxi
tak-dcxi / initializeSplitText.ts
Last active April 26, 2024 07:37
initializeSplitText
type AccordionOptions = {
duration?: number
easing?: string
}
const defaultOptions: AccordionOptions = {
duration: 300,
easing: 'ease-in-out',
}
@tak-dcxi
tak-dcxi / initializeObserveAnimation.ts
Last active April 24, 2024 10:21
initializeObserveAnimation
export type ObserverOptions = {
root?: HTMLElement | null;
rootMargin?: string;
threshold?: number | number[];
};
const defaultOptions: ObserverOptions = {
root: null,
rootMargin: "0px",
threshold: 0
@tak-dcxi
tak-dcxi / initializeSmoothScroll.ts
Last active April 23, 2024 12:19
initializeSmoothScroll
const initializeSmoothScroll = (): void => {
// クリックイベントのリスナーを追加
document.addEventListener('click', handleClick, { capture: true })
}
// 固定配置のヘッダーのブロックサイズを取得
const getHeaderBlockSize = (): string => {
const header = document.querySelector('[data-fixed-header]') as HTMLElement
if (!header) return '0'
@tak-dcxi
tak-dcxi / initializeTabs.ts
Last active May 7, 2024 02:37
initializeTabs
export type TabsOptions = {
tablistSelector: string | undefined
tabSelector: string | undefined
tabpanelSelector: string | undefined
firstView?: number
}
const defaultOptions: TabsOptions = {
tablistSelector: undefined,
tabSelector: undefined,