Skip to content

Instantly share code, notes, and snippets.

@harapeko
Last active August 9, 2019 05:56
Show Gist options
  • Save harapeko/ec50117dfabfb7fc4412b912de3b7c56 to your computer and use it in GitHub Desktop.
Save harapeko/ec50117dfabfb7fc4412b912de3b7c56 to your computer and use it in GitHub Desktop.
対象先をトグルクラスするjs
# SEE: https://codepen.io/harapeko/pen/KWobXR
class ToggleTarget
init: =>
$(document).off 'click'
$(document).on 'click', '.js-toggle', (event)->
event.preventDefault()
$btn = $ @ #clickした要素
$(document).off 'click', '.js-toggle'
$target = if $btn.data 'toggle-class' then $btn.data 'toggle-class' else '-active'
$("##{$target}").toggleClass $class
$ =>
toggle = new ToggleTarget
toggle.init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment