Created
February 22, 2020 17:06
-
-
Save mio-U-M/57771180ea41afa76227aba9ae99ae03 to your computer and use it in GitHub Desktop.
functions for stylus
This file contains 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
/** | |
* 画像サイズを返してくれる。 | |
* @param {String} パス | |
*/ | |
img-size($path) | |
image-size($img_dir + $path) | |
/** | |
* 画像アスペクト比を返してくれる。 | |
* @param {String} パス | |
* @param {String} 基準 | |
*/ | |
img-aspect($path, $base = 'width') | |
$size = img-size($path) | |
$base == 'width' ? $size[1] / $size[0] : $size[0] / $size[1] | |
/** | |
* 単位がvwのwidth基準heightを返す。 | |
* @param {String} パス | |
* @param {Number} サイズ | |
*/ | |
dynamic-height($path, $size = 100) | |
$aspect = img-aspect($path) | |
unit($aspect * $size, 'vw') | |
/** | |
* 単位がvhのheight基準widthを返す。 | |
* @param {String} パス | |
* @param {Number} サイズ | |
*/ | |
dynamic-width($path, $size = 100) | |
$aspect = img-aspect($path, 'height') | |
unit($aspect * $size, 'vh') | |
/** | |
* PC用の大きさにしてくれる。 | |
* @param {Number} サイズ | |
*/ | |
pc-size($size) | |
$size * $pc_scale | |
/** | |
* SP用の大きさにしてくれる。 | |
* @param {Number} サイズ | |
*/ | |
sp-size($size) | |
$size * $sp_scale | |
/** | |
* デザインのサイズを元に、0 ~ 100vwの大きさにしてくれる。 | |
*/ | |
dynamic-size($size, $ua = 'pc') | |
$baseSize = $ua == 'pc' ? $pc_design_width : $sp_design_width | |
unit(($size / $baseSize) * 100, 'vw') | |
/** | |
* ランダム数値を返す。 | |
*/ | |
random($val) | |
math(math(0, 'random') * $val + 1, 'floor') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment