Skip to content

Instantly share code, notes, and snippets.

@colelawrence
Last active August 29, 2015 14:03
Show Gist options
  • Save colelawrence/e6d51ff3afa53db34636 to your computer and use it in GitHub Desktop.
Save colelawrence/e6d51ff3afa53db34636 to your computer and use it in GitHub Desktop.
Wait for an element to calculate a offsetWidth before a calculation
do renderBouncer = ->
if inlineImgEl.offsetWidth isnt 0
inlineImgEl.style.height = (inlineImgEl.offsetWidth / ratio) + "px"
else if inlineImgEl.renderOffsetWidthTries++ > 20
inlineImgEl.style.height = (width / ratio) + "px"
else
setTimeout(renderBouncer, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment