Created
April 5, 2012 11:18
-
-
Save yusugomori/2310033 to your computer and use it in GitHub Desktop.
hoverQueue.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Usage | |
# | |
# **html** | |
# <a href="#" class="elem"> | |
# hoverTrigger | |
# <div class="pop"> | |
# In the pop | |
# </div> | |
# </a> | |
# | |
# **js** | |
# $(function(){ | |
# hoverTrigger(".elem", ".pop"); | |
# }); | |
# | |
# **coffee** | |
# $ -> | |
# hoverTrigger ".elem", ".pop" | |
# | |
# | |
hoverTrigger = (elem,pop) -> | |
queue = [] # ホバーアクションを追加するキュー | |
# cssで指定していない場合 | |
# $(pop).css | |
# display: "none" | |
hover_on = (t) -> | |
$(t).find(pop).fadeTo(87, 1) | |
return true | |
hover_off = (t) -> | |
stop() | |
$(t).find(pop).fadeOut(87) | |
return true | |
$(elem).hover -> | |
queue.push(hover_on) # ホバー開始時にキューに追加 | |
setTimeout => | |
if queue.length > 0 | |
func = queue.shift() | |
if typeof func is "function" | |
func(@) | |
, 370 # アクションを実行するまでの待機時間 | |
, -> | |
if queue.length > 0 | |
queue.shift() # ホバーが外れたらアクションをキャンセル | |
else | |
hover_off(@) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment