123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="bg"></div>
<div class="wrap flex">
	<div class="cat">
		<div class="face">
			<div class="ears">
				<div class="ear ear-left flex"></div>
				<div class="ear ear-right flex"></div>
			</div>
			<div class="eyes">
				<div class="eye eye-left flex">
					<div class="eye-iris eye-iris-left flex">
						<div class="eye-pupil eye-pupil-left flex"></div>
					</div>
				</div>
				<div class="eye eye-right flex">
					<div class="eye-iris eye-iris-right flex">
						<div class="eye-pupil eye-pupil-right flex"></div>
					</div>
				</div>
			</div>
			<div class="nose"></div>
			<div class="whisker-pads">
				<div class="whisker-pad whisker-pad-left">
					<div class="pores pores-left flex">
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
					</div>
					<div class="whiskers whiskers-left flex">
						<div class="whisker whisker-1"></div>
						<div class="whisker whisker-2"></div>
						<div class="whisker whisker-3"></div>
					</div>
				</div>
				<div class="whisker-pad whisker-pad-right">
					<div class="pores pores-right flex">
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
						<div class="pore flex"></div>
					</div>
					<div class="whiskers whiskers-right flex">
						<div class="whisker whisker-1"></div>
						<div class="whisker whisker-2"></div>
						<div class="whisker whisker-3"></div>
					</div>
				</div>
			</div>
			<div class="mouth"></div>
		</div>
		<p class="message">mousemove!</p>
	</div>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Baloo+Bhaina');
$white:#fff;
$black:#333333;
$beige:#F58E7E;
$orange:#F26752;
$gray:darken($white,
30%);
$grayLight:darken($white,
7%);
$grayLighter:darken($white,
4%);
$green:#58BE89;
$navy:#27313D;
@mixin center {
	align-items: center;
	justify-content: center;
}

@mixin circle {
	border-radius: 100%;
}

* {
	box-sizing: border-box;
}

.flex {
	display: flex;
}

html,
body,
.wrap {
	/* .catをFlexboxでウィンドウ中央に配置するため */
	height: 100%;
}

body {
	background: $navy;
}
.bg{
	background:rgba(#000,.2);
	position:fixed;
	top:0;
	left:0;
	height:100%;
	width:50%;
	z-index:10000;
}
.wrap {
	/* .catをウィンドウ中央に配置 */
	@include center;
}

.cat {
	height: 150px;
	width: 200px;
}

.face {
	background: $grayLight;
	@include circle;
	height: inherit;
	position: relative;
}

.ears {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	z-index: -1;
}

.ear {
	background: $grayLight;
	border-radius: 30px;
	/* .ear::beforeを.earの中央に配置 */
	@include center;
	height: 80px;
	position: absolute;
	top: -6px;
	width: 80px;
	&::before {
		background: $beige;
		border-radius: 23px;
		content: '';
		height: 73px;
		width: 73px;
	}
	&-left {
		left: 14px;
		/* rotateで回転、skewX,Yで傾斜変形させて猫耳の形に近づける */
		transform: rotate(25deg) skewX(30deg) skewY(8deg);
	}
	&-right {
		right: 14px;
		/* .ear-leftの逆 */
		transform: rotate(-25deg) skewX(-30deg) skewY(-8deg);
	}
}

.eyes {
	height: 40px;
	position: absolute;
	top: 40%;
	left: 0;
	transform: translateY(-40%);
	width: 100%;
}

.eye {
	background: $black;
	border: 2px solid $black;
	@include center;
	height: 35px;
	overflow: hidden;
	position: absolute;
	top: 0;
	width: 45px;
	/* 虹彩 */
	&-iris {
		background: $green;
		@include center;
		height: 40px;
		width: 40px;
	}
	&-iris,
	&-pupil,
	&-pupil::before {
		@include circle;
	}
	/* 瞳 */
	&-pupil {
		background: $black;
		@include center;
		height: 35px;
		width: 35px;
		/* 瞳の光 */
		&::before {
			background: $white;
			content: '';
			height: 6px;
			width: 6px;
		}
	}
	&-left {
		border-radius: 0 70% 0 70%;
		left: 30px;
	}
	&-right {
		border-radius: 70% 0 70% 0;
		right: 30px;
	}
}


/* 鼻筋 */

.nose {
	/* border-top,left,rightで台形を作っている */
	border-top: 20px solid $grayLight;
	border-left: 2px solid transparent;
	border-right: 2px solid transparent;
	height: 20px;
	position: absolute;
	top: 56%;
	left: 50%;
	transform: translate(-50%, 0%);
	width: 50px;
	z-index: 3;
	/* 鼻 */
	&::before {
		background: $orange;
		border-radius: 40%;
		content: '';
		height: 30px;
		position: absolute;
		top: -6px;
		left: 50%;
		transform: translateX(-50%);
		width: 50px;
		z-index: 1;
	}
}

.whisker-pads {
	position: absolute;
	left: 50%;
	bottom: 0;
	transform: translateX(-50%);
	z-index: 4;
	>.whisker-pad {
		@include circle;
		&-left,
		&-right {
			background: $grayLighter;
			border-bottom: 1px solid $gray;
			height: 44px;
			position: absolute;
			bottom: 2px;
			width: 60px;
		}
		&-left {
			border-right: 2px solid $gray;
			left: 50%;
			transform: translateX(-98%);
		}
		&-right {
			border-left: 2px solid $gray;
			right: 50%;
			transform: translateX(98%);
		}
	}
}

.pores {
	flex-wrap: wrap;
	height: 30px;
	position: absolute;
	top: 50%;
	width: 50px;
	&-left {
		left: 50%;
		transform: skewX(5deg) translate(-50%, -50%);
	}
	&-right {
		right: 50%;
		transform: skewX(-5deg) translate(50%, -50%);
	}
	>.pore {
		@include center;
		height: (100% / 3);
		width: (100% / 3);
		&::before {
			background: $gray;
			@include circle;
			content: '';
			display: block;
			height: 3px;
			width: 3px;
		}
	}
}

.whiskers {
	flex-wrap: wrap;
	align-content: space-around;
	height: 100%;
	position: absolute;
	top: 0;
	width: 100%;
	&-left {
		transform: translateX(-50%);
		.whisker {
			&-2 {
				transform: skewY(-10deg);
			}
			&-3 {
				transform: skewY(-20deg);
			}
		}
	}
	&-right {
		transform: translateX(50%);
		.whisker {
			&-2 {
				transform: skewY(10deg);
			}
			&-3 {
				transform: skewY(20deg);
			}
		}
	}
	>.whisker {
		flex-direction: column;
		border-top: 1px solid $gray;
		border-top-left-radius: 50%;
		border-top-right-radius: 50%;
		height: 10px;
		width: 100%;
	}
}

.mouth {
	background: $grayLight;
	@include circle;
	height: 55px;
	position: absolute;
	bottom: -9px;
	left: 50%;
	transform: translateX(-50%);
	width: 90px;
}

.message {
	display:none;
	color: $white;
	font-size: 28px;
	font-family: 'Baloo Bhaina', cursive;
	margin-top: 30px;
	text-align: center;
}
            
          
!
            
              (() => {
	
	//ウィンドウサイズ
	let width: number;
	let height: number;

	//白猫の目に関するクラス
	class Eye {
		private _pupil: HTMLElement;
		
		constructor(sel) {

			//瞳
			this._pupil = document.querySelector(sel);
		}
		
		get pupil(): HTMLElement {
			return this._pupil;
		}
	}
	
	//eyeLeftオブジェクトとeyeRightオブジェクトを生成
	const eyeLeft: Eye = new Eye('.eye-pupil-left');
	const eyeRight: Eye = new Eye('.eye-pupil-right');
	
	//配列に格納
	const eyes: Eye[] = [eyeLeft, eyeRight];
	
	//ポインターに関するクラス
	class Pointer {
		constructor() {
			
			//mousemoveされたらmoveメソッドを実行
			window.addEventListener('mousemove', (e) => this.move(e));
		}
		
		//マウスが動いたら実行される。瞳を動かす関数
		move(e): void {
			
			//e.preventDefault();
			
			//ポインターの座標
			const mouseX: number = e.clientX;
			const mouseY: number = e.clientY;
			
			//ウィンドウサイズ
			width = window.innerWidth;
			height = window.innerHeight;
			
			//ウィンドウ横中央(width/2)の座標からみたポインターのx相対座標(mouseX)
			//ウィンドウ横中央(width/2)の座標からポインターのx相対座標(mouseX)までの距離
			//https://syncer.jp/javascript-reverse-reference/get-mouse-position
			const distanceX: number = mouseX - width / 2;//底辺
			
			//ウィンドウ縦中央(height/2)の座標からみたポインターのy相対座標(mouseY)
			//ウィンドウ縦中央(height/2)の座標からポインターのy座標(mouseY)までの距離
			const distanceY: number = mouseY - height / 2;//高さ
			
			//ウィンドウ中央からポインターまでの距離。長さ。ベクトル(量・方向)
			//ピタゴラスの定理によって斜辺の長さdistanceを算出
			const distance: number = Math.sqrt(Math.pow(distanceX, 2) + Math.pow(distanceY, 2));
			
			//底辺distanceX、高さdistanceYのときのラジアン(度数法でいう角度)
			//ラジアンとは国際単位系 (SI) における角度(平面角)の単位。半径の長さと弧の長さの比(弧 / 半径)で得ることができる。半径と弧の長さが同じであるラジアンは1ラジアン
			//atan2メソッドは高さと底辺を引数とすることでラジアン(アークタンジェント)を得ることができる。
			//引数としてdistanceXに対するdistanceYの割合(tan)を渡す。
			const rad: number = Math.atan2(distanceY, distanceX);

			//ウィンドウ中央からポインターまでを線で引いたときの線の傾きつまり角度を併せ持った座標
			//Math.cos(rad) = rad度のときのcos。Math.cos(rad)は全体であるradを1としたときのそれに対するcos(底辺(半径)の割合)
			//distance * Math.cos(rad) = distanceを掛けることで全体であるradを1からdistanceに変換。つまり、全体がdistanceであるradに対するcos(底辺(半径)の割合)。
			
			
			
			///console.log(Math.cos(rad));
			///console.log(Math.tan(rad));
			
			//translateX,Yに値を入れる必要があるため、sinとcosに分ける
			//Math.cos: cosrad°ということ。傾きを1としたときのそれに対する横方向cos(底辺・半径)の比(割合)を求めることができる。
			//distanceを掛けることで傾きをdistanceとしたときの底辺の比(正確な底辺の長さ)がわかる。
			//distanceを掛けるということ→distance * cos / distance * 1
			const x: number = distance * Math.cos(rad);
			
			const y: number = distance * Math.sin(rad);
			
			//ポインターの動きに応じて、瞳を決められた範囲内で動かす
			for(let i = 0; i < eyes.length; i++) {
				eyes[i].pupil.style.transform = 'translateX(' + Pointer.clamp(x / 28, -10, 10) + 'px)' + 'translateY(' + Pointer.clamp(y / 28, -10, 10) + 'px)';
			}
			console.log(Pointer.clamp(x / 28, -10, 10));
		}
		
		//numberをminからmaxまでの値で返す
		static clamp(number, min, max): number {
			return Math.max(min, Math.min(number, max));
		}
	}

	//pointerオブジェクト生成
	const pointer: Pointer = new Pointer;
})();
//http://www.tohoho-web.com/js/math.htm

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console