SOURCE

console 命令行工具 X clear

                    
>
console
$(function () {
    $('.d1').on('mouseenter mouseleave', function(e) {
        var w = $(this).width();
        var h = $(this).height();
        var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
        var y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
        var xy = Math.round( ( ( (Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
        var eventType = e.type;
        var oName = ['上方', '右侧', '下方', '左侧'];
        if(e.type == 'mouseenter') {
            $(this).text(oName[xy] + '进入');
        } else {
            $(this).text(oName[xy] + '离开'); 
        }
    });
});
<div class="d1">鼠标进入前</div>
.d1 {
    width: 400px;
    height: 400px;
    background: #555;
    color: #fff;
    margin: 200px auto;
    font: 30px/400px Microsoft YaHei;
    text-align: center;
}

本项目引用的自定义外部资源