0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaScriptだけ(ライブラリなし)でオフキャンバスドロワー

Last updated at Posted at 2023-09-05

ライブラリなし、素のJavaScriptでもオフキャンバスドロワーが作れます。

💡ポイントは以下のように「JSからスタイルを指定」すること。

❌「JSでクラスを付け替えてCSSでスタイル変更」
 ではうまくアニメーションしませんでした。

drawer.js

	// メニューを開く
	function openMenu() {
		// アイコン変形、ナビエリアvisible
		hamburger.classList.add(CLASS);
		menu.classList.add(CLASS);

		// ヘッダーを左へ移動
		header.style.transform = "translateX(-300px)";
		header.style.transition = "all 0.3s ease-in-out";

		// コンテンツ部分を左へ移動
		contents.style.transform = "translateX(-300px)";
		contents.style.transition = "all 0.3s ease-in-out";

		// マスクON
		headerMask.classList.add(maskOn);
		contentsMask.classList.add(maskOn);

		// 背面コンテンツ固定
		backgroundFix(true);
		hamburger.setAttribute("aria-expanded", "true");
		flg = true;
	}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?