css实现三维立体小球checkbox开关效果代码

代码语言:html

所属分类:表单美化

代码描述:css实现三维立体小球checkbox开关效果代码

代码标签: css 三维 立体 小球 checkbox 开关

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 223;
	--bg: hsl(var(--hue),90%,70%);
	--fg: hsl(var(--hue),90%,10%);
	--primary: hsl(var(--hue),90%,50%);
	--trans-dur: 0.3s;
	font-size: calc(60px + (120 - 60) * (100vw - 320px) / (2560 - 320));
}
body,
input {
	font: 1em/1.5 sans-serif;
}
body {
	background-color: var(--bg);
	color: var(--fg);
	display: flex;
	height: 100vh;
	transition:
		background-color var(--trans-dur),
		color var(--trans-dur);
}
.tilt-toggle,
.tilt-toggle__input {
	position: relative;
}
.tilt-toggle {
	margin: auto;
	perspective: 480px;
}
.tilt-toggle__input,
.tilt-toggle__input:before,
.tilt-toggle__input:after,
.tilt-toggle__input-ball {
	animation: tiltOffA 0.6s ease-in-out forwards;
	display: block;
}
.tilt-toggle__input,
.tilt-toggle__input:before,
.tilt-toggle__input:after {
	border-radius: 0.75em;
}
.tilt-toggle__input {
	background-image:
		linear-gradient(90deg,hsla(var(--hue),90%,40%,0) 20%,hsla(var(--hue),90%,40%,0.5) 30% 70%,hsl(var(--hue),90%,40%) 80%),
		linear-gradient(hsl(var(--hue),90%,80%) 33%,hsl(var(--hue),90%,30%) 67%);
		border-radius: 0.75em;
	filter: grayscale(0.9);
	outline: transparent;
	width: 3em;
	height: 1.5em;
	-webkit-appearance: none;
	appearance: none;
	-webkit-tap-highlight-color: transparent;
}
.tilt-toggle__input:before,
.tilt-toggle__input:after {
	content: "";
	position: absolute;
}
.tilt-toggle__input:before {
	animation-name: tiltOffB;
	background-color: var(--primary);
	box-shadow: 0 0 max(1px,0.05em) max(1px,0.05em) var(--primary);
	top: 0.125em;
	left: 0.125em;
	width: calc(100% - 0.25em);
	height: calc(100% - 0.25em);
}
.tilt-toggle__input:after {
	animation-name: shadowOff;
	background-color: hsla(var(--hue),90%,10%,0.7);
	filter: blur(0.1em);
	top: 0.2em;
	left: 0.2em;
	width: 100%;
	height: 100%;
	transform-origin: 0.75em 50%;
	z-index: -1;
}
.tilt-toggle__input-ball {
	animation-name: rollOff;
	background-color: hsl(0,0%,100%);
	border-radius: 50%;
	box-shadow:
		-0.05em -0.05em 0.1em hsl(var(--hue),10%,80%) inset,
		-0.25em -0.25em 0.25em hsl(var(--hue),10%,60%) inset,
		0.15em 0.15em 0.0625em hsla(var(--hue),10%,10%,0.7);
	position: absolute;
	top: 0.25em;
	left: calc(50% - 0.5em);
	width: 1em;
	height: 1em;
	transform: translate3d(-0.75em,0,0.3em);
}
.tilt-toggle__sr {
	overflow: hidden;
	position: absolute;
	width: 1px;
	height: 1px;
}

/* :checked */
.tilt-toggle__input:checked {
	animation-name: tiltOnA;
	filter: grayscale(0);
}
.tilt-toggle__input:checked:befor.........完整代码请登录后点击上方下载按钮下载查看

网友评论0