效果图:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>鼠标的移入和移出事件</title>
<style>
.box{
width: 200px;
height: 200px;
margin: 300px;
border: 1px solid #999;
position: relative;
overflow: hidden;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
// js 判断鼠标移入移除的方向
/**
* @param { object } params
* element: 元素
* maskStyle: 遮罩样式
* transitionTime:过渡时间
* openLeave: 是否开启移出动画
*
* @returns undefined
*/
function setMaskFollowMouse(params){
const {
element,maskStyle,transitionTime='1s',openLeave=true } = params
// 添加鼠标移入事件
element.addEventListener('mouseover',function(e<