【发布时间】:2018-01-11 20:49:05
【问题描述】:
我正在尝试将 this 代码 sn-p 从 JS 移植到 Coffee,但卡在忽略代码的设置超时函数上,超时时根本没有添加任何类:
$ ->
$('.click').click ->
$span = $(this).closest('span')
$this = $(this)
if $span.hasClass('fa-star')
$this.removeClass 'active'
setTimeout (->
$this.removeClass 'active-2'
), 30
$this.removeClass 'active-3'
setTimeout (->
$span.removeClass 'fa-star'
$span.addClass 'fa-star-o'
), 15
else
$this.addClass 'active'
$this.addClass 'active-2'
setTimeout (->
$span.addClass 'fa-star'
$span.removeClass 'fa-star-o'
), 150
setTimeout (->
$this.addClass 'active-3'
), 150
尝试提取函数,但这也无济于事。
【问题讨论】:
标签: javascript jquery coffeescript