Skip to content

Instantly share code, notes, and snippets.

@kyleturman
Created August 23, 2013 13:10
Show Gist options
  • Save kyleturman/6319195 to your computer and use it in GitHub Desktop.
Save kyleturman/6319195 to your computer and use it in GitHub Desktop.
strong {
display: inline-block;
font-weight: normal;
overflow: hidden;
margin-top: 2px;
position: relative;
vertical-align: top;
span {
display: block;
position: absolute;
white-space: pre;
}
}
<h1>
SOLVING THE AGE-OLD QUESTION OF<br>
<q>&ldquo;</q>WHERE SHOULD WE EAT <strong><span>ON Friday?</strong><q>&rdquo;</q>
</h1>
times = ["Tonight?", "Tomorrow?", "This Weekend?", "Next Week?", "Right Now?"]
timeChangeCount = 5
# Get the span and set initial width
$span = $tagline.find("span")
$when = $tagline.find("strong").css {width: $span.width(), height: $span.height()}
changeTime = ()->
if timeChangeCount < times.length
$span = $when.find("span")
# Create a new span and set it beneath the old one
$newSpan = $('<span/>',
html: times[timeChangeCount]
style: "top:30%;opacity:0"
).appendTo($when)
# Animate the new width to containing strong
$when.animate {width: $newSpan.width(), height: $newSpan.height()}, 250
# Out with old, in with the new
$span.animate {opacity:0}, 200, ()->
$newSpan.animate {top:0, opacity:1}, 800, "easeOutElastic", ()->
$span.remove()
timeChangeCount++
setTimeout(changeTime, 1500)
setTimeout(changeTime, 2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment