繁体   English   中英

单击图片显示弹出窗口的最佳方法是什么?

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

这里我有一个jsFiddle

您可以看到现在有3张播放器图像我想要的是每当我单击图像时,它应该在播放器下方显示弹出窗口。

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

所以我的问题是执行此操作的最佳方法是什么

我可能在浪费一些东西,就像..

-是否点击图片,我应该更改弹出图片以及span标签文本的位置。

-我应该为每个玩家提供一个弹出窗口,然后隐藏并显示它们

或其他您可以建议的方法。它将对我有很大帮助。


  
 
  
  
  
#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>


 

谢谢您提前为我度过时间。谢谢。

<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>

脚本:

$("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;
}

演示: https : //jsfiddle.net/astm1o3p/21/

在这里在弹出窗口的CSS中设置chqnges

position:absolute;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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