Created
August 12, 2014 10:55
-
-
Save ameyamashiro/f521d9f573a29dd39f5e to your computer and use it in GitHub Desktop.
Size Computer
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() { | |
var SizeComputer, _computeWidth; | |
_computeWidth = function(originWidth, baseWidth, refWidth) { | |
var rate; | |
rate = originWidth / baseWidth; | |
return refWidth * rate; | |
}; | |
SizeComputer = function(varArgs) { | |
var defaults, opts, tgtCurWidth, verticalRate; | |
defaults = { | |
originWidth: 0, | |
originHeight: 0, | |
baseWidth: 800, | |
maxBaseWidth: 800, | |
refWidth: $(window).width() | |
}; | |
opts = $.extend(defaults, {}, varArgs); | |
if (opts.refWidth >= opts.maxBaseWidth) { | |
opts.refWidth = opts.maxBaseWidth; | |
} | |
tgtCurWidth = _computeWidth(opts.originWidth, opts.baseWidth, opts.refWidth); | |
verticalRate = opts.originHeight / opts.originWidth; | |
return { | |
width: tgtCurWidth, | |
height: Math.round(tgtCurWidth * verticalRate) | |
}; | |
}; | |
window.SizeComputer = SizeComputer; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment