Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there
I am looking for a way to display a div on a linkbutton is clicked and the div should be next to the link button when it display
what i have got is the css applied to div is
CSS
. Bag div.MultibuyModal
{
/*border:8px solid #a1a1a1;*/
background-color:  #FFFFFF;
width: 340px; 
padding-left:30px;
padding-top:5px; 
height:150px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;  
overflow-y:scroll;
position:fixed;
top: 75%;
left: 50%;   
margin-top: -9em; /*set to a negative number 1/2 of your height*/
margin-left: -15em; /*set to a negative number 1/2 of your width*/
border: 10px solid rgb(100, 100, 100); /* default color */
border: 10px solid rgba(0, 0, 0, 0.1);  /*rgba for transparency */
}


but the issue with the above css is dive is always on the fixed position what i want is the when the linkbutton is clicked div should display next to the link button and when use scroll the page div also should move along with the page move.
if some one could show me a example would be much help full
thanks
Posted

1 solution

Hi,
Assuming your DIV and LinkButton are
ASP.NET
<asp:linkbutton runat="server" id="lnkShow" text="Show Div" onclientclick="return ShowDiv();" ></asp:linkbutton>
<div id="DivToShow" style="display: none; position: fixed; padding: 3px; -webkit-border-radius: 10px;-moz-border-radius: 10px; border-radius: 10px; border: 1px solid; z-index: 50000; width: auto; background: #d3e499;">
    Content of the div
</div>
and then add below javascript/jQuery code to your page to get the position where the DIV to show
JavaScript
var mouseX = 0;
   var mouseY = 0;
   $(document).ready(function () {
       $(document).mousemove(function (event) {
           mouseX = Math.round(event.clientX);
           mouseY = Math.round(event.clientY + 15);
       });
   });
   function ShowDiv() {
       $('#DivToShow').css({ 'top': mouseY + 'px', 'left': mouseX + 'px' }).fadeIn('slow');
   }
Hope this will help you.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900