<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta name="renderer" content="webkit" />
<meta name="force-rendering" content="webkit" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<title>测试</title>
<link href="../images/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16" />
<link href="../images/favicon-48x48.png" rel="icon" type="image/png" sizes="48x48" />
<link rel="stylesheet" href="./css/typo.css" />
<style>
.content {
position: relative;
width: 800px;
height: 800px;
margin: 70px auto;
border: 1px solid #f00;
}
.x1 {
position: absolute;
left: 50%;
top: 50%;
width: 150px;
height: 150px;
line-height: 150px;
border-radius: 50%;
background-color: #f00;
color: #fff;
transform: translate(-50%, -50%);
text-align: center;
}
</style>
</head>
<body>
<div id="info"></div>
<div class="content" id="content">
<div class="x1" id="x1">(400, 400)</div>
</div>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/lodash.min.js"></script>
<script>
(function ($, undefined) {
const $x1 = $('#x1');
const $content = $('#content');
const $info = $('#info');
$content.on('mousemove', function (e) {
if (e.target.id === $content.attr('id')) {
const { offsetX, offsetY } = e;
const x = offsetX - 400;
const y = offsetY - 400;
const xie = Math.round(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)))
$x1.css({
"box-shadow": `${x / 24}px ${y / 24}px 15px rgba(125, 125, 125, 0.3)`,
})
$info.text(`(${x}, ${y}) -> ${xie}`)
}
})
})(jQuery);
</script>
</body>
</html>
效果
根据鼠标位置 ,生成的阴影