virtual-joystick
Version:
Virtual Joystick is a simple, reusable custom web element for touch-enabled user interfaces.
168 lines • 3.3 kB
CSS
html {
scroll-behavior: smooth;
}
body {
font-family: 'Roboto', sans-serif;
}
h2 {
pointer-events: none;
margin-block: 0 20px;
grid-column-start: 1;
grid-column-end: 3;
user-select: none;
}
.joystick-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
padding: 20px;
position: relative;
border-radius: 10px;
}
.playground {
display: flex;
min-height: 150px;
justify-content: center;
align-items: center;
user-select: none;
}
.joystick-container:target:before {
content: '';
inset: 10px;
display: block;
border: 4px solid yellow;
position: absolute;
}
.fixed,
.dynamic {
border: 1px dashed;
& virtual-joystick {
width: 100%;
height: 100%;
}
}
.dynamic:before {
content: "Tap here to start";
position: absolute;
}
#static {
background-color: #748ffc;
}
#semi {
background-color: #9775fa;
}
#dynamic {
background-color: #da77f2;
}
#lock {
background-color: #f783ac;
}
#shape {
background-color: #ff8787;
}
#transition {
background-color: #ffa94d;
}
#style {
background-color: #ffd43b;
}
#slotted {
background-color: #a9e34b;
}
#size {
background-color: #69db7c;
}
#fixed {
background-color: #38d9a9;
}
.container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(max(320px, calc(33% - 24px)), 1fr));
grid-gap: 12px;
}
.square::part(joystick),
.square::part(joystick):before,
.square::part(joystick):after {
border-radius: 0;
}
.bounce::part(joystick),
.bounce::part(joystick):before,
.bounce::part(joystick):after {
border-radius: 14px;
}
.bounce::part(joystick):after {
transition-timing-function: cubic-bezier(.17, .67, .52, 1.48);
}
.bounce::part(active):after {
transition-timing-function: ease;
}
.custom::part(joystick) {
background-color: rgba(31, 223, 108, 0.4);
}
.custom::part(joystick):after {
background-color: rgba(31, 223, 108, 0.6);
}
.slotted::part(joystick):after {
z-index: 1;
}
.arrow {
fill: rgba(255, 255, 255, 0.4);
stroke:gray;
stroke-width: 1px;
}
.arrow-bottom {
left: 55px;
top: 100px;
position: absolute;
}
.arrow-right {
left: 100px;
top: 55px;
rotate: 270deg;
position: absolute;
}
.arrow-top {
left: 55px;
top: 5px;
rotate: 180deg;
position: absolute;
}
.arrow-left {
left: 5px;
top: 55px;
rotate: 90deg;
position: absolute;
}
.custom::part(joystick),
.custom::part(joystick):before,
.custom::part(joystick):after {
border: 0;
}
.size {
--radius: 60px;
}
.size::part(joystick),
.size::part(joystick):before,
.size::part(joystick):after {
background-color: transparent;
border: 7px solid #673ab7;
}
.size::part(joystick):before,
.size::part(joystick):after {
width: 70px;
height: 70px;
}
.size::part(joystick) {
border-width: 2px;
}
.size::part(joystick):before {
border-width: 4px;
}
.output {
pointer-events: none;
user-select: none;
padding-left: 50px;
white-space: pre;
}
[data-mode="fixed"]::part(joystick) {
transform: translate(40px, 40px);
}