Skip to content

Instantly share code, notes, and snippets.

@raine
Created September 27, 2011 19:53
Show Gist options
  • Select an option

  • Save raine/1246044 to your computer and use it in GitHub Desktop.

Select an option

Save raine/1246044 to your computer and use it in GitHub Desktop.
$ ->
return unless $('#pages_home').length
$(window).blur ->
disableLoop()
$(window).focus ->
enableLoop() if not window.cInt?
fadeDuration = 1000
items = ($ elem for elem in $ '.right')
current = 0
_(items.length).times ->
$('<span>').addClass('dot').appendTo('#ctrl')
$('#ctrl .dot:first').addClass('active')
dots = $('#ctrl .dot')
disableLoop = ->
clearInterval window.cInt if window.cInt?
delete window.cInt
enableLoop = ->
disableLoop()
window.cInt = setInterval showNext, 10000
dots.click ->
disableLoop()
setTimeout enableLoop, 10000
showItem $(this).index()
activateDot = (i) ->
dots.removeClass 'active'
$(dots[i]).addClass 'active'
showItem = (i, delayDot) ->
return if i == current
items[current].fadeOut fadeDuration
items[i].fadeIn fadeDuration, ->
activateDot i if delayDot
activateDot i unless delayDot
current = i
showNext = ->
nextIndex = ->
return 0 if current + 1 == items.length
current + 1
showItem nextIndex(), true
enableLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment