Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Things to consider #1

Open
soerenmeier opened this issue Dec 4, 2023 · 3 comments
Open

Things to consider #1

soerenmeier opened this issue Dec 4, 2023 · 3 comments

Comments

@soerenmeier
Copy link
Owner

async function openChange(open) {
if (isOpen === open)
	return;

isOpen = open;

if (open) {
	if (!probedHeight) {
		subEl.classList.add('probe');
		probedHeight = subEl.offsetHeight;
		subEl.classList.remove('probe');
	}

	gsap.to(subEl, {
		height: probedHeight,
		clearProps: 'height',
		onStart: () => {
			subEl.classList.add('open');
		}
	});
} else {
	gsap.to(subEl, {
		height: 0,
		clearProps: 'height',
		onComplete: () => {
			subEl.classList.remove('open');
		}
	});
}
}
$: openChange(open);
@soerenmeier
Copy link
Owner Author

const transition = new GenTransition;
	transition.setTransition(async function*(open, wasRunning) {
		// close
		if (!open) {
			ctnEl.classList.remove('open');
			yield 500;
			ctnEl.classList.remove('visible');
			return;
		}

		// let's probe the height if we're not cancelling an animation
		if (!wasRunning) {
			// check the height
			ctnEl.classList.add('probe-height');
			const height = ctnEl.clientHeight;
			ctnEl.classList.remove('probe-height');
			ctnEl.style.setProperty('--height', height + 'px');
			yield 32;
		}

		ctnEl.classList.add('visible');
		yield 32;

		ctnEl.classList.add('open');
	});
	$: !transition.firstCall() ? transition.update(open) : null;

@soerenmeier
Copy link
Owner Author

const transition = new GenTransition;
	transition.setTransition(async function*(open, wasRunning) {
		if (!menuEl)
			return;

		const a = cls => menuEl.classList.add(cls);
		const r = cls => menuEl.classList.remove(cls);

		if (open) {
			document.documentElement.classList.add('no-scroll');

			a('stage-1');
			yield 32;
			a('stage-2');
			yield 200;
			a('stage-3');
		} else {
			r('stage-3');
			r('stage-2');
			yield 500;
			r('stage-1');

			document.documentElement.classList.remove('no-scroll');
		}
	});
	$: !transition.firstCall() ? transition.update(open) : null;

@soerenmeier
Copy link
Owner Author

	function onClick(e) {
		open = !open;

		if (open) {
			gsap.to(ctnEl, {
				height: ctnEl.scrollHeight,
				duration: .5,
				clearProps: 'maxHeight',
				onStart: () => {
					ctnEl.classList.add('open');
				}
			});
		} else {
			gsap.to(ctnEl, {
				height: 0,
				duration: .5,
				clearProps: 'height',
				onStart: () => {
					ctnEl.classList.remove('open');
				}
			});
		}
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant