简体   繁体   中英

what is the best way to show the pop-up on click of an image?

Here I have a jsFiddle

you can See there are 3 images of Players now What I want is Whenever I click on the image it should show the pop-up below the players.

Player can be In any position it will not be in a grid

so My question is What is the best way perform this.

I have something in my probably the wast it is like..

-- whether onclick of an Image I should change the position of the position of the popup image as well as span tag's text.

-- I should provide a popup to the every Player and just hide and show them

or something else you can suggest.It will help me a lot.


  
 
  
  
  
#player-back{
    height:250px; 
    background:#0F0;
}
#p1{
    margin-top:50px;
    margin-left:80px;
}
#p2{
    margin-left:150px;
}
#p3{
    margin-left:200px;
}
#player-popup{
     
    background:orange;
        height:27px;
        width:85px;
        border-radius:10px;
        text-align:center;
        margin-left:50px;

}
   

<div id='player-back'>
        <img src='http://s6.postimg.org/su0e7812l/player1.png' id='p1'/>
        <img src='http://s6.postimg.org/afpv38orx/player2.png' id='p2'/>
        <img src='http://s6.postimg.org/h7ga63drh/player3.png' id='p3'/>
            <div id='player-popup'>
                <span>Player1</span>
            </div>
    </div>


 

Thank you for spending time for me in advance Thank you.

<div id='player-back'>
<img src='http://s6.postimg.org/su0e7812l/player1.png' data-playerid="1" id='p1'/>
<img src='http://s6.postimg.org/afpv38orx/player2.png' data-playerid="2" id='p2'/>
<img src='http://s6.postimg.org/h7ga63drh/player3.png' data-playerid="3" id='p3'/>
    <div id='player-popup' style="display:none">
        <span>Player1</span>
    </div>
 </div>

Script:

$("img").click(function(){
var top = $(this).offset().top + $(this).width() + 2;
var left = $(this).offset().left - $(this).height() / 2;  
$("#player-popup span").text("Player "+$(this).data("playerid")); 
$("#player-popup").css({ top: top, left: left }).show();

});

css:

#player-back{
height:250px; 
background:#0F0;
}
#p1{
margin-top:50px;
margin-left:80px;
}
#p2{
margin-left:150px;
}
#p3{
margin-left:200px;
}
#player-popup{
background:orange;
height:27px;
width:85px;
border-radius:10px;
text-align:center;
position:absolute;
}

Demo: https://jsfiddle.net/astm1o3p/21/

Here make chqnges in the css for popup set

position:absolute;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM