Skip to content

Instantly share code, notes, and snippets.

@mio-U-M
Created February 22, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mio-U-M/57771180ea41afa76227aba9ae99ae03 to your computer and use it in GitHub Desktop.
Save mio-U-M/57771180ea41afa76227aba9ae99ae03 to your computer and use it in GitHub Desktop.
functions for stylus
/**
* 画像サイズを返してくれる。
* @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