define([], function () { 'use strict'; /** * 画像のサイズ調節用の関数を返す * 親のBox要素は次のスタイルを指定しておく * * - overflow: hidden * - position: relative * - width: 任意の値 * - height: 任意の値 * / 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)), 'position': 'absolute' }); } else { // 縦長の画像の場合は横をフルに使う $img.css({ 'width': boxWidth, 'top': -1 * Math.floor(boxHeight/2 * (height/width - 1)), 'position': 'absolute' }); } return $img; } } return { createImageAdjustFn: createImageAdjustFn } });