意思搞的不是太明白,先发上来做为一个记录。

 

window.onload = function(){
            
var a = document.getElementById('a');
            a.onmousemove 
= function(e){
                
var pointer = getCroodsInDocument(e);
                
var b = document.getElementById('b');
                b.innerHTML 
= 'x, y = (' + pointer.x + ',' + pointer.y + ')';
            }
            
            
function getCroodsInDocument(e){
                e 
= e || window.event;
                
var x = e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
                
var y = e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
                
return {
                    
'x': x,
                    
'y': y
                };
            }
        }

 

静态代码:

 

<div id="a">
            
<div id="c"></div>
        
</div>
        
<div id="b">x</div>

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2022-01-08
  • 2022-01-08
  • 2022-01-01
  • 2021-10-11
相关资源
相似解决方案