CSS
语言:
CSSSCSS
确定
:root {
--mouse-x: 200;
--mouse-y: 200;
}
/* See: http://stackoverflow.com/q/40164169/4172644*/
div::after {
counter-reset: mouse-x var(--mouse-x) mouse-y var(--mouse-y);
content: counter(mouse-x) "px, " counter(mouse-y) "px";
}
/* setup and presentation styles */
div::before {
content: 'mouse position';
font-weight: bold;
}
div {
position: fixed;
top: 0;
left: 0;
-webkit-transform: translate(calc(var(--mouse-x) * 1px), calc(var(--mouse-y) * 1px));
transform: translate(calc(var(--mouse-x) * 1px), calc(var(--mouse-y) * 1px));
width: 10em;
height: 10em;
background: #9ccf5e;
color: #fff;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: column;
-ms-flex-flow: column;
flex-flow: column;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
line-height: 2;
border-radius: 100%;
will-change: transform;
}
body {
margin: 2em;
font-family: sans-serif;
}