Skip to content

Instantly share code, notes, and snippets.

@hagino3000
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save hagino3000/4560e4be81e55749314c to your computer and use it in GitHub Desktop.

Select an option

Save hagino3000/4560e4be81e55749314c to your computer and use it in GitHub Desktop.
画像の真ん中をいい感じに切り取るスクリプト
define([], function () {
'use strict';
function createImageAdjustFn(boxWidth, boxHeight) {
return function($img) {
var width = $img.width();
var height = $img.height();
if (width > height) {
$img.css({
'height': boxHeight,
'left': -1 * Math.floor(boxWidth/2 * (width/height - 1))
});
} else {
$img.css({
'width': boxWidth,
'top': -1 * Math.floor(boxHeight/2 * (height/width - 1))
});
}
return $img;
}
}
return {
createImageAdjustFn: createImageAdjustFn
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment