zoukankan      html  css  js  c++  java
  • 准确判断鼠标指针是否在对象里

    function mouseMove(ev)
    {  
        ev= ev || window.event;
        var mousePos = mouseCoords(ev);
                
        if (currentMenu) {
            var xIn = currentMenu.offsetLeft < mousePos.x && ((currentMenu.offsetLeft + currentMenu.offsetWidth) > mousePos.x);
            var yIn = currentMenu.offsetTop < mousePos.y && ((currentMenu.offsetTop + currentMenu.offsetHeight) > mousePos.y);
                    
            if ((xIn && yIn)) {
                document.getElementById('bb').value = 'in';
            } else {
                document.getElementById('bb').value = 'out';
            }
        }
    }

    function mouseCoords(ev)
    {
        if(ev.pageX || ev.pageY){
            return {x:ev.pageX, y:ev.pageY};
        }
        return {
            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop     - document.body.clientTop
        };
    }

    document.onmousemove = mouseMove;
  • 相关阅读:
    高级打字机
    不等数列
    间谍网络
    医院设置
    题目编号生成器
    传纸条
    聪明的打字员
    倒水问题
    八数码难题
    生日蛋糕
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/1549943.html
Copyright © 2011-2022 走看看