LoginSignup
0
0

More than 3 years have passed since last update.

【JSメモ】ハンバーガーのトグルアクション

Posted at

はじめに

ここでのトグルアクションは、

開くときは、ハンバーガーボタンで開く。
閉じるときは、画面のどこを押しても閉じる

で実装したいと思います。

コード

sample.js
// SP用:ハンバーガーのトグルアクション
$(document).on('click', function(e) {
  if($(e.target).is('#hamburger')) {
    $('.c-header__nav').toggleClass('c-header__is-active');
  } else if($(e.target).is('*')) {
    $('.c-header__nav').removeClass('c-header__is-active');
  }
});
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