SOURCE

console 命令行工具 X clear

                    
>
console
div.addEventListener('mouseenter',function(e){
    let getStyle = val=>parseFloat( getComputedStyle(this,null)[val] )

    let Wid = getStyle('width')
    let Hei= getStyle('height')

    let arr = [//这4个值,那个值最小 鼠标就是从那个方向进入的
      e.offsetY,
      Wid-e.offsetX,
      Hei-e.offsetY,
      e.offsetX]

    let mini = arr[0]
    let miniIndex = 0
    arr.forEach((item,index)=>{
      if(item<mini){
        mini = item;//更新最小值
        miniIndex = index;//更新索引
      }
    })

    function setTime(top,right){
      hhc.style.top = top
      hhc.style.right = right
      hhc.style.transition = 'none'
      setTimeout(()=>{
        hhc.style.top = 0
        hhc.style.right = 0
        hhc.style.transition = '.5s'
      },10)
    }
    let posList = [
      ['-100%','0'],
      ['0','-100%'],
      ['100%','0'],
      ['0','100%']
    ]
    setTime(...posList[miniIndex])
  })
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <div id="div"><div id="hhc"></div></div>
</body>
</html>
html,body{width:100%;height:100%;}
#div{
  width:200px;
  height:200px;
  border:1px solid;
  position: absolute;
  left: 50%;
  top: 50%;
  transform:translate(-50%,-50%);
  overflow: hidden;
}
#hhc{
  position: absolute;
  
  width:100%;
  height:100%;
  background: red;
  top:100%;
  right:100%;

}