gsap+Draggable实现可拖动调节的极简恒温器效果代码
代码语言:html
所属分类:拖放
代码描述:gsap+Draggable实现可拖动调节的极简恒温器效果代码
代码标签: gsap Draggable 拖动 调节 极简 恒温器
下面为部分代码预览,完整代码请点击下载或在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=Montserrat:wght@300;400;500&display=swap'> <style> * { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --hue: 223; --bg: hsl(var(--hue),10%,70%); --fg: hsl(var(--hue),10%,10%); --primary: hsl(var(--hue),90%,55%); --trans-dur: 0.3s; font-size: calc(16px + (20 - 16) * (100vw - 320px) / (1280 - 320)); } body, button { font: 1em/1.5 Montserrat, sans-serif; } body { background-color: var(--bg); color: var(--fg); height: 100vh; display: grid; place-items: center; transition: background-color var(--trans-dur), color var(--trans-dur); } .t, .t__inner, .t__inner:before, .t__inner:after, .t__drag { border-radius: 50%; } .t { --temp-hue: 50; box-shadow: 0 0 0.1em hsl(var(--hue),10%,90%), 0 0 0.3em hsl(var(--hue),10%,80%), 0 0 0.1em hsl(var(--hue),10%,40%) inset; display: grid; place-items: center; position: relative; width: 16em; height: 16em; transition: box-shadow 0.3s; z-index: 0; } .t__inner { background-color: hsl(var(--hue),10%,80%); position: relative; width: 11.5em; height: 11.5em; transition: background-color 0.3s; } .t__inner:before, .t__inner:after { content: ""; display: block; position: absolute; } .t__inner:before { background-image: linear-gradient(hsl(var(--hue),10%,95%),hsl(var(--hue),10%,65%)); top: -0.25em; left: -0.25em; width: 12em; height: 12em; z-index: -1; } .t__inner:after { background-image: linear-gradient(hsl(var(--temp-hue),90%,100%),hsl(var(--temp-hue),90%,50%)); box-shadow: 0 -0.25em 2em hsla(var(--temp-hue),90%,55%,0.3), 0 2em 1em hsl(var(--temp-hue),20%,55%); top: -0.25em; left: -0.375em; width: 12.25em; height: 12.25em; z-index: -2; } .t__drag, .t__value, .t__units { position: absolute; } .t__drag, .t__unit { background: transparent; -webkit-appearance: none; appearance: none; } .t__drag { cursor: grab; display: block; width: 100%; height: 100%; z-index: 2; -webkit-tap-highlight-color: transparent; } .t__drag:focus { outline: transparent; } .t__arrows { display: block; position: absolute; top: -2.25em; left: -2.25em; opacity: 0; width: 16em; height: auto; transition: opacity 0.15s linear; z-index: 1; } .t__drag:not(.t__drag--dragging):hover ~ .t__arrows { opacity: 1; transition-delay: 0.3s; } .t__drag--dragging ~ .t__arrows { opacity: 0; transition-delay: 0s; } .t__drag--dragging ~ .t__units { z-index: 0; } .t__value, .t__unit { text-shadow: 0 0.15em 0.1em hsla(var(--hue),10%,10%,0.1); } .t__value { display: flex; justify-content: flex-end; align-items: center; padding-right: 3em; inset: 0; z-index: 0; } .t__digit, .t__degree { display: inline-block; line-height: 1; -webkit-user-select: none; user-select: none; } .t__digit { font-size: 3em; font-weight: 300; text-align: center; width: 1ch; } .t__degree { color: hsl(var(--hue),10%,50%); font-size: 2em; transform: translateY(-0.5ch); } .t__units { top: calc(50% - 1.5em); right: 1.5em; z-index: 3; } .t__unit { color: hsl(var(--hue),10%,65%); display: block; font-size: 1em; font-weight: 500; line-height: 1; width: 1.5em; height: 1.5em; } .t__unit[aria-pressed="true"] { color: currentColor; } .t__sr { clip: rect(1px,1px,1px,1px); overflow: hidden; position: absolute; width: 1px; height: 1px; } /* Dark theme */ @media (prefers-color-scheme: dark) { :root { --bg: hsl(var(--hue),10%,20%); --fg: hsl(var(--hue),10%,90%); } .t { box-shadow: 0 0 0.1em hsl(var(--hue),10%,40%), 0 0 0.3em hsl(var(--hue),10%,30%), 0 0 0.1em hsl(var(--hue),10%,0%) inset; } .t__inner { background-color: hsl(var(--hue),10%,30%); } .t__inner:before { background-image: linear-gradient(hsl(var(--hue),10%,45%),hsl(var(--hue),10%,15%)); } .t__inner:after { background-image: linear-gradient(hsl(var(--temp-hue),90%,10%),hsl(var(--temp-hue),90%,50%)); box-shadow: 0 -0.25em 2em hsla(var(--temp-hue),90%,55%,0.3), 0 2em 1em hsl(var(--temp-hue),20%,25%); } .t__value { text-shadow: 0 0.15em 0.1em hsla(var(--hue),10%,10%,0.2); } .t__degree { color: hsl(var(--hue),10%,70%); } .t__unit { color: hsl(var(--hue),10%,45%); } } </style> </head> <body > <div class="t"> <div class="t__inner"> <div class="t__value"> <span class="t__digit" data-temp>-</span><span class="t__digit" data-temp>-</span><span class="t__degree">°</span> </div> <button class="t__drag" type="button" data-drag> <span class="t__sr" data-temp-sr>--</span> </button> <svg class="t__arrows" width="256px" height="256px" viewBox="0 0 256 256"> <g fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="roun.........完整代码请登录后点击上方下载按钮下载查看
网友评论0