Div display on same position where mouse clicked but window focus go on top

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gskoli
    New Member
    • May 2010
    • 23

    Div display on same position where mouse clicked but window focus go on top

    Dear all ,
    I am giving you snippet of the code , where i have taken div which is i have put above the row of one table and[br] on mouse click changing the position of the div and showing it as per the x-y coordinate but every time suppose i have scroll the it again goes to to top...[br]

    Code:
            function setVisible(t,e,obj)
            {
                    if(e || t){
                            var posx = 0; var posy = 0;
                            if (!e){var e = window.event;}
                            if (e.pageX || e.pageY){alert('ONe');
                                    posx = e.pageX;
                                    posy = e.pageY;
                                    //if(document.body.scrollTop){
                                    //      posy = posy + document.body.scrollTop;
                                    //}
                            }
                            else if (e.clientX || e.clientY){ alert('TwO'); //for IE
                                    posx = e.clientX;
                                    posy = e.clientY;
                                    if(document.body.scrollTop){
                                            posy = posy + document.body.scrollTop;
                                    }
    
                            } //alert(posx+'::'+posy);
                            //document.getElementById(obj).style.cursor = "hand";
                            alert(document.body.scrollTop);
                            document.getElementById(obj).style.left = posx+'px';
                            document.getElementById(obj).style.top = posy+'px';
                    }
                    var obj = document.getElementById(obj); alert(obj.style.display+'HHHHHH'+ obj.style.left+'###'+ obj.style.top);
                    obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
            }
    
    <body >
      <table>
    <tr>
    
    </tr>
    <div id='layer1'>
    </div>
    // Some loop to print rows
    <tr>
      <a href= '#' onclick="setVisible(this,event,'layer1');" >Bunti </a>
    </tr>
    //loop over  
     </table>
    </body >
    Please help me out
Working...