欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery計算鼠標(biāo)和指定元素之間距離的方法

 更新時間:2015年06月26日 11:53:34   作者:不吃皮蛋  
這篇文章主要介紹了jquery計算鼠標(biāo)和指定元素之間距離的方法,涉及jQuery針對頁面位置屬性與鼠標(biāo)事件的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了jquery計算鼠標(biāo)和指定元素之間距離的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

(function() {
  var mX, mY, distance,
    $distance = $('#distance span'),
    $element = $('#element');
  function calculateDistance(elem, mouseX, mouseY) {
    return Math.floor(Math.sqrt(Math.pow(mouseX - (elem.offset().left+(elem.width()/2)), 2) + Math.pow(mouseY - (elem.offset().top+(elem.height()/2)), 2)));
  }
  $(document).mousemove(function(e) { 
    mX = e.pageX;
    mY = e.pageY;
    distance = calculateDistance($element, mX, mY);
    $distance.text(distance);     
  });
})();

希望本文所述對大家的jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論