mouse posioin on ibject ????

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Beshoo

    mouse posioin on ibject ????

    Do u have any idea how can i detect if the mouse on acertain object
    for exapmle I have <divi wnat if the mouse on this <divtake an
    action ????

  • -Lost

    #2
    Re: mouse posioin on ibject ????

    "Beshoo" <basheermoro@gm ail.comwrote in message
    news:1177081792 .686787.207440@ y5g2000hsa.goog legroups.com...
    Do u have any idea how can i detect if the mouse on acertain object
    for exapmle I have <divi wnat if the mouse on this <divtake an
    action ????


    -Lost


    Comment

    • Elegie

      #3
      Re: mouse posioin on ibject ????

      Beshoo wrote:
      Do u have any idea how can i detect if the mouse on acertain object
      for exapmle I have <divi wnat if the mouse on this <divtake an
      action ????
      There are many events that you can monitor to do that (check the link
      offered by Lost). Many approaches are possible: you can watch the
      mousemove event, which is fired each time the mouse moves over on
      element (but not when the mouse does not move anymore), or watch the
      mouseover and mouseout events, to define some mouse state for your
      element (beware of event bubbling). See below.

      ---
      <head>
      <style type="text/css">
      div {background-color:yellow; margin:10px}
      </style>
      </head>
      <body ondblclick="ale rt('Is the mouse over foo: ' + m())">
      <div id="info">Doubl e click anywhere.</div>
      <div id="foo">I am foo!</div>
      <div id="not-foo">I am not foo!</div>
      <script type="text/javascript">
      // --- get some monitor function ---//
      var m=monitorMouseM oveForElement(
      document.getEle mentById("foo")
      );

      // --- lib ---//
      function monitorMouseMov eForElement(ele m) {
      var isMouseOver = false;

      _e(elem, "onmouseover",f unction (evt) { isMouseOver=tru e; });
      _e(elem, "onmouseout ",
      function (evt) {
      isMouseOver = contains(
      this, (evt=evt||windo w.event, evt.relatedTarg et||evt.toEleme nt)
      );
      }
      );

      function contains(cer, cee){
      if(cer.contains ) {
      return cer.contains(ce e);
      } else if(typeof cee.parentNode! = "undefined" ) {
      return (function(cr, ce){
      return cr==ce ||
      ce&&ce.parentNo de&&arguments.c allee(cr,ce.par entNode)||
      false ;
      })(cer, cee);
      } else {
      return false;
      }
      }

      function _e(obj, evt, func) {
      if(obj[evt]) {
      obj[evt] = (function(x){
      return function (evt) {
      func.call(this, evt);
      return x.call(this, evt);
      }
      })(obj[evt]);
      } else {
      obj[evt] = func ;
      }
      }

      return function() {
      return isMouseOver;
      };
      }
      </script>
      </body>
      ---


      HTH,
      Elegie.

      Comment

      • prince@dyumnin.com

        #4
        Re: mouse posioin on ibject ????

        On Apr 20, 8:37 pm, "-Lost" <missed-s...@comcast.ne twrote:
        "Beshoo" <basheerm...@gm ail.comwrote in message
        >
        news:1177081792 .686787.207440@ y5g2000hsa.goog legroups.com...
        >
        Do u have any idea how can i detect if the mouse on acertain object
        for exapmle I have <divi wnat if the mouse on this <divtake an
        action ????
        >
        http://www.w3.org/TR/DOM-Level-2-Eve...nts-eventgroup...
        >
        -Lost
        How about onhover ?
        HTH
        Prince
        --

        Dyumnin.com specializes in cutting-edge ASIC and FPGA design, RISC-V, AI, Networking, PCIe IP, and comprehensive SoC development.


        Comment

        Working...