zoukankan      html  css  js  c++  java
  • 【鼠标】位置

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <style type="text/css">
        #tip{ position:absolute; background:#ffc; color:#333; font:14px/1.5 arial;}
        </style>
        <div id="tip">
            <span id="tip-left"></span> | <span id="tip-top"></span>
        </div>
        
        <script>
        document.onmousemove = function (e) {        
            var posx = 0, posy = 0,
                e = e || window.event,
                get = function (id) {
                    return document.getElementById(id);
                },
                tip = get('tip'), tipLeft = get('tip-left'), tipTop = get('tip-top');    
            if (e.pageX || e.pageY) {
                posx = e.pageX;
                posy = e.pageY;
            } else if (e.clientX || e.clientY) {
                posx = e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
                posy = e.clientY + document.documentElement.scrollTop + document.body.scrollTop;
            };    
            tip.style.top = +posy + 15 + 'px';
            tip.style.left = +posx + 15 + 'px';    
            tipLeft.innerHTML = 'Left: ' + posx;
            tipTop.innerHTML = 'Top: ' + posy;        
        };
        </script>
    </body>
    </html>
  • 相关阅读:
    JPA 系列教程1-环境搭建
    微信企业号接收消息(使用SpringMVC)
    oracle xe 数据库用户操作
    eclipse快捷键
    堆和栈的区别(重要)
    synchronized的4种用法
    servlet匹配规则和顺序
    JAVA中的枚举
    JSON对象操作
    Handler
  • 原文地址:https://www.cnblogs.com/jzm17173/p/2568537.html
Copyright © 2011-2022 走看看