v 0. Pasted by sbmaxx as javascript at 2010-06-07 21:00:20 MSK and set expiration to never.

Paste will expire never.

  1. "use strict";
  2. /*global $*/
  3. function getElementCoordinates(el) {
  4.   return {
  5.     left: el.offsetLeft,
  6.     right: el.offsetLeft + el.offsetWidth,
  7.     top: el.offsetTop,
  8.     bottom: el.offsetTop + el.offsetHeight
  9.   };
  10. }
  11. function checkIntersection($el) {
  12.   var pointer = getElementCoordinates($('#mypointer')[0]);
  13.   var element = getElementCoordinates($el[0]);
  14.  
  15.   if ((pointer.left >= element.left && pointer.left <= element.right) ||
  16.     (pointer.right >= element.left && pointer.right <= element.right) ||
  17.     (pointer.bottom >= element.bottom && pointer.bottom <= element.top) ||
  18.     (pointer.top >= element.bottom && pointer.top <= element.top)) {
  19.     return true;
  20.   } else {
  21.     return false;
  22.   }
  23. }
  24. $(function () {
  25.   $('#mypointer').live('click mouseover', function (e) {
  26.     //here write selectors you want to check for collision
  27.     $('h1').each(function () {
  28.       if (checkIntersection($(this))) {
  29.         $(this).trigger(e.type);
  30.         return false;
  31.       }
  32.     });
  33.   });
  34.   $('h1').live('click mouseover', function (e) {
  35.     $("#output").html(e.type + ' fired on ' + e.target.nodeName);
  36.   });
  37. });


Editing is locked.