Skip to content

Instantly share code, notes, and snippets.

@1v
Created March 31, 2017 13:08
Show Gist options
  • Save 1v/2f357bfb4f451c655608ec2c0ff2c525 to your computer and use it in GitHub Desktop.
Save 1v/2f357bfb4f451c655608ec2c0ff2c525 to your computer and use it in GitHub Desktop.
resize_images = (resize = false) ->
resize_single = (that) ->
if that.height() <= 200
that.css({'width': 'auto', 'height': '100%'})
else
that.css({'width': '100%', 'height': 'auto'})
resize_process = (that) ->
# change dimensions to original
that.css({'width': 'auto', 'height': 'auto'})
# fit parent box
resize_single(that)
# scaling for fill
resize_single(that)
images = $('.image img')
images.each ->
if resize
resize_process($(this))
else
$(this).load ->
resize_process($(this))
resize_images()
$(window).resize ->
resize_images(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment