js+css实现带表情滑块拖拽星级评分效果代码

代码语言:html

所属分类:星级评分

代码描述:js+css实现带表情滑块拖拽星级评分效果代码

代码标签: js css 表情 滑块 拖拽 星级 评分

下面为部分代码预览,完整代码请点击下载或在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">

    <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=DM+Sans&amp;display=swap'>

    <style>
        * {
        	border: 0;
        	box-sizing: border-box;
        	margin: 0;
        	padding: 0;
        }
        :root {
        	--hue: 223;
        	--white: hsl(var(--hue),10%,100%);
        	--lt-gray: hsl(var(--hue),10%,95%);
        	--gray1: hsl(var(--hue),10%,90%);
        	--gray2: hsl(var(--hue),10%,80%);
        	--gray7: hsl(var(--hue),10%,30%);
        	--gray9: hsl(var(--hue),10%,10%);
        	--primary: hsl(var(--hue),90%,55%);
        	--trans-dur: 0.3s;
        	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320));
        }
        body,
        input {
        	font: 1em/1.5 "DM Sans", sans-serif;
        }
        body {
        	background-color: var(--white);
        	color: var(--gray9);
        	height: 100vh;
        	display: grid;
        	place-items: center;
        	transition:
        		background-color var(--trans-dur),
        		color var(--trans-dur);
        }
        
        /* Main styles */
        .fr {
        	animation: fade-slide-in 0.6s ease-out;
        	padding: 0 1.5em;
        	max-width: 20em;
        }
        .fr__face {
        	--face-hue1: 60;
        	--face-hue2: 30;
        	background-image:
        		linear-gradient(
        			135deg,
        			hsl(var(--face-hue1),90%,55%),
        			hsl(var(--face-hue2),90%,45%)
        		);
        	border-radius: 50%;
        	box-shadow: 0 0.5em 0.75em hsla(var(--face-hue2),90%,55%,0.3);
        	margin: 0 auto 2em;
        	position: relative;
        	width: 3em;
        	height: 3em;
        }
        .fr__face-right-eye,
        .fr__face-left-eye,
        .fr__face-mouth-lower,
        .fr__face-mouth-upper {
        	position: absolute;
        	transition:
        		background-color var(--trans-dur),
        		box-shadow var(--trans-dur),
        		color var(--trans-dur);
        }
        .fr__face-right-eye,
        .fr__face-left-eye {
        	background-color: var(--white);
        	border-radius: 50%;
        	top: 0.75em;
        	width: 0.6em;
        	height: 0.6em;
        }
        .fr__face-right-eye {
        	--delay-right: 0s;
        	animation: right-eye 1s var(--delay-right) linear paused;
        	clip-path: polygon(0 75%,100% 0,100% 100%,0 100%);
        	left: 0.6em;
        }
        .fr__face-left-eye {
        	--delay-left: 0s;
        	animation: left-eye 1s var(--delay-left) linear paused;
        	clip-path: polygon(0 0,100% 75%,100% 100%,0 100%);
        	right: 0.6em;
        }
        .fr__face-mouth-lower,
        .fr__face-mouth-upper {
        	color: var(--white);
        	top: 1.75em;
        	left: 0.75em;
        	width: 1.5em;
        	height: 0.75em;
        }
        .fr__face-mouth-lower {
        	--delay-mouth-lower: 0s;
        	animation: mouth-lower 1s var(--delay-mouth-lower) linear paused;
        	border-radius: 50% 50% 0 0 / 100% 100% 0 0;
        	box-shadow: 0 0.125em 0 inset;
        }
        .fr__face-mouth-upper {
        	--delay-mouth-upper: 0s;
        	animation: mouth-upper 1s var(--delay-mouth-upper) linear paused;
        	border-radius: 0 0 50% 50% / 0 0 100% 100%;
        	box-shadow: 0 -0.125em 0 inset;
        }
        .fr__label {
        	display: block;
        	margin-bottom: 1.5em;
        	text-align: center;
        }
        .fr__input {
        	--input-hue: 60;
        	--percent: 50%;
        	background-color: var(--gray1);
        	background-image: linear-gradient(hsl(var(--input-hue),90%,45%),hsl(var(--input-hue),90%,45%));
        	background-size: var(--percent) 100%;
        	background-repeat: no-repeat;
        	border-radius: 0.25em;
        	display: block;
        	margin: 0.5em auto;
        	width: 100%;
        	max-width: 10em;
        	height: 0.5em;
        	transition: background-color var(--trans-dur);
        	-webkit-appearance: none;
        	appearance: none;
        	-webkit-tap-highlight-color: transparent;
        }
        .fr__input:focus {
        	outline: transparent;
        }
        
        /* WebKit */
        .fr__input::-webkit-slider-thumb {
        	background-color: var(--white);
        	border: 0;
        	border-radius: 50%;
        	box-shadow: 0 0.125em 0.5em hsl(0,0%,0%,0.3);
        	width: 1.5em;
        	height: 1.5em;
        	transition: background-color 0.15s linear;
        	-webkit-appearance: none;
        	appearance: none;
        }
        .fr__input:focus::-webkit-slider-thumb,
        .fr__input::-webkit-slider-thumb:hover {
        	background-color: var(--lt-gray);
        }
        
        /* Firefox */
        .fr__input::-moz-range-thumb {
        	background-color: var(--white);
        	border: 0;
        	border-radius: 50%;
        	box-shadow: 0 0.125em 0.5em hsl(0,0%,0%,0.3);
        	width: 1.5em;
        	height: 1.5em;
        	transition: background-color 0.15s linear;
        }
        .fr__input:focus::-moz-range-thumb,
        .fr__input::-moz-range-thumb:hover {
        	background-color: var(--lt-gray);
        }
        
        /* `:focus-visible` support */
        @supports selector(:focus-visible) {
        	.fr__input:focus::-webkit-slider-thumb {
        		background-color: var(--white);
        	}
        	.fr__input:focus-visible::-webkit-slider-thumb,
        	.fr__input::-webkit-slider-thumb:hover {
        		background-color: var(--lt-gray);
        	}
        	.fr__input:focus::-moz-range-thumb {
        		background-color: var(--white);
        	}
        	.fr__input:focus-visible::-moz-range-thumb,
        	.fr__input::-moz-range-t.........完整代码请登录后点击上方下载按钮下载查看

网友评论0