Skip to content

Instantly share code, notes, and snippets.

@ICarpenter
Created May 26, 2014 20:34
Show Gist options
  • Save ICarpenter/0c30d304dee899741fd4 to your computer and use it in GitHub Desktop.
Save ICarpenter/0c30d304dee899741fd4 to your computer and use it in GitHub Desktop.
ngular.module('Fn')
.factory('ImageService', function () {
return {
calculateOffset: function(width, height) {
if (width === height) {
return false;
}
var bigger, smaller, side;
var style = {};
if(width > height) {
bigger = width;
smaller = height;
side = 'top';
} else {
bigger = height;
smaller = width;
side = 'left';
}
style[side] = (((bigger - smaller) / bigger) * 50) + '%';
return style;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment