Created
August 6, 2011 23:05
-
-
Save davidbrooks/1129863 to your computer and use it in GitHub Desktop.
Tests to see whether the targeted image is a vertical or horizontal image and adds the appropriate class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function check_image_orientation(image_to_check){ | |
$(image_to_check).load(function(){ | |
function orient_image() { | |
var image_width = parseInt(image_to_check.width()); | |
var image_height = parseInt(image_to_check.height()); | |
if (image_height <= image_width) { | |
$(image_to_check).addClass('horizontal_image'); | |
} else { | |
$(image_to_check).addClass('vertical_image'); | |
} | |
} | |
setTimeout(orient_image, 0); | |
}); | |
}; | |
$('document').ready(function(){ | |
var image_to_check = $('#photos #main_content p img'); | |
check_image_orientation(image_to_check); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment