Skip to content

Instantly share code, notes, and snippets.

@davidbrooks
Created August 6, 2011 23:05
Show Gist options
  • Save davidbrooks/1129863 to your computer and use it in GitHub Desktop.
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.
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