Skip to content

Instantly share code, notes, and snippets.

@mio-U-M
mio-U-M / hexToRgb.js
Last active August 24, 2020 11:52
Color code exchange. Return rgb value as array.
function hexToRgb(color) {
// remove # if exist
const replacedColor = color.replace(/#/g, "");
return [
parseInt(replacedColor.substr(0, 2), 16),
parseInt(replacedColor.substr(2, 2), 16),
parseInt(replacedColor.substr(4, 2), 16)
];
}
// textures should be object
export function threeTextureLoad(textures) {
const texturePromises = [];
const loadedTextures = {};
const loader = new THREE.TextureLoader();
Object.keys(textures).forEach(key => {
texturePromises.push(
new Promise((resolve, reject) => {
const entry = textures[key];
@mio-U-M
mio-U-M / getDate.js
Last active May 13, 2020 10:27
日付を分割して返却する
function getDate(d) {
const date = new Date(d)
return (
date.getFullYear() +
'.' +
(date.getMonth() + 1) +
'.' +
date.getDate() +
' ' +
this.days[date.getDay()]
@mio-U-M
mio-U-M / before-and-after-mixin.scss
Created February 22, 2020 17:07
擬似要素のテンプレで書くところを省略するためのmixin
@mixin simple-before {
&::before {
content: '';
@content;
}
}
@mixin simple-after {
&::after {
content: '';
@mio-U-M
mio-U-M / position-abs.scss
Created February 22, 2020 17:07
absoluteを指定する時いちいち全部書かなくていいようにしたものです
@mixin position-ab($top: auto, $right: auto, $bottom: auto, $left: auto) {
position: absolute;
margin: auto;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
@mio-U-M
mio-U-M / position-ab-center2.scss
Last active March 26, 2020 07:11
position:absoluteで中央よせ
@mixin position-ab-center1 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
@mio-U-M
mio-U-M / image-url.scss
Created February 22, 2020 17:06
背景画像を取ってくるscss
$img_dir: '/img/';
@function image-url ($url) {
@return url("#{$img_dir}#{$url}");
}
// image-urlを使う想定
@mixin bg-contain($path) {
background-image: image-url($path);
background-repeat: no-repeat;
background-size: contain;
}
@mio-U-M
mio-U-M / size-scale-by-vw.scss
Created February 22, 2020 17:06
画面に応じて拡大縮小できるようにvwにして返してくれる
// size
$pc-min-width: 1440px;
$tablet_max_width: 769px;
$sp_max_width: 375px;
@function pSize($value) {
@return $value / $pc_min_width * 100 + vw;
}
@function tSize($value) {
@mio-U-M
mio-U-M / _function.styl
Created February 22, 2020 17:06
functions for stylus
/**
* 画像サイズを返してくれる。
* @param {String} パス
*/
img-size($path)
image-size($img_dir + $path)
/**
* 画像アスペクト比を返してくれる。
* @param {String} パス