Skip to content

Instantly share code, notes, and snippets.

@hrumhrumble
Created September 6, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrumhrumble/6fe633e18feb88d4f61ca9252bffc01d to your computer and use it in GitHub Desktop.
Save hrumhrumble/6fe633e18feb88d4f61ca9252bffc01d to your computer and use it in GitHub Desktop.
intervals = []
isPaused = false
isBublOnTop = (bulb) ->
$(bulb).position().top + $(bulb).height() <= 0
bulbStop = (bulb) ->
clearInterval()
bulbMoveTop = (bulb, index) ->
tick = 0
bottom = parseInt($(bulb).css('bottom'))
right = parseInt($(bulb).css('right'))
left = parseInt($(bulb).css('left'))
bottomTick = Math.random() + 0.5
createInterval = ->
interval = setInterval(->
unless isPaused
tick += 2
if isBublOnTop(bulb)
bulbInit(bulb)
bulbMoveTop(bulb)
$(bulb).removeClass('fullpage-geli__bulb--bubling') if $(bulb).hasClass('fullpage-geli__bulb--small')
clearInterval(interval)
else
$(bulb).css({ 'bottom': Math.round(bottom + (tick * bottomTick)), 'left': Math.round(left + (tick / 6)) }) if $(bulb).prop('style')['left'] != ''
$(bulb).css({ 'bottom': Math.round(bottom + (tick * bottomTick)), 'right': Math.round(right + (tick / 6)) }) if $(bulb).prop('style')['right'] != ''
$(bulb).css({ 'bottom': Math.round(bottom + (tick * 1.2)) }) if $(bulb).hasClass('fullpage-geli__bulb--small')
$(bulb).css({ 'bottom': Math.round(bottom + (tick * 1.4)) }) if $(bulb).hasClass('fullpage-geli__bulb--mini')
$(bulb).addClass('fullpage-geli__bulb--bubling') if $(bulb).hasClass('fullpage-geli__bulb--small')
, _.random(12, 14))
intervals.push(interval)
createInterval()
bulbInit = (bulb) ->
minWidth = 200
maxWidth = $(window).width() - $('.fullpage-geli__bulb').width() * 1.5
rightOrLeftCss = _.sample([{'right': _.random(minWidth, maxWidth)}, {'left': _.random(minWidth, maxWidth)}])
bottomCss = {'bottom': -$('.fullpage-geli__bulb').height()}
css = _.merge(bottomCss, rightOrLeftCss)
$(bulb).css({'right': '', left: ''})
$(bulb).css(css);
bulbsInit = ->
bulbs = $('.fullpage-geli__bulb')
_.each(bulbs, (bulb) ->
bulbInit(bulb)
)
init = ->
$('.fullpage-geli__bulb').not('.fullpage-geli__bulb--small').on 'click', ->
if $(this).hasClass('fullpage-geli__bulb--paused')
isPaused = false
$(this).removeClass('fullpage-geli__bulb--paused')
else
$('.fullpage-geli__bulb').removeClass('fullpage-geli__bulb--paused')
$(this).addClass('fullpage-geli__bulb--paused')
isPaused = true
bulbsInit()
_.each($('.fullpage-geli__bulb'), (bulb, i) ->
bulbMoveTop(bulb)
)
$(document).on('page:change', init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment