这是我的小提琴:http://jsfiddle.net/Ya3w7/2/
HTML:
<img src="http://cdn.tacky.me/m/static/settings16.png" class="settings-icon"/>
<div id="control-panel">
<img src="http://cdn.tacky.me/m/static/settings16.png" />
<a href="#" style="float:right" id="close-cp">X</a>
<div class="link_container"><a href="#">Show Profile</a></div>
</div>CSS:
.settings-icon
{
margin: 100px;
cursor: pointer;
}
#control-panel
{
position: absolute;
height: auto;
width: auto;
top: 0;
left: 0;
background-color: #fff;
font-family: Arial, sans-serif;
display: none;
z-index: 4;
}JavaScript:
$('.settings-icon').click(function(){
$('#control-panel').position({
of: $('.settings-icon'),
my: 'left top',
at: 'left top'
});
$('#control-panel').show();
});
$('#close-cp').click(function(event){
event.preventDefault();
$('#control-panel').hide();
});我想做什么:我有一个设置图像,点击它就会在这个img周围定位一个绝对定位的div (称为contgrol面板)。
我所看到的:
当我第一次点击img时,它工作得很好。
我通过单击右上角的X来取消控制面板
第二次单击控制面板时,显示在其他地方。
如何复制
到小提琴那儿去
发布于 2013-03-26 21:13:04
您只需要将控制面板关闭后返回到0,0。这是最新的小提琴http://jsfiddle.net/Ya3w7/3/。
$('.settings-icon').click(function(){
$('#control-panel').position({
of: $(this),
my: 'left top',
at: 'left top'
});
$('#control-panel').show();
});
$('#close-cp').click(function(event){
event.preventDefault();
$('#control-panel').css({top: '0px', left: '0px'}).hide();
});发布于 2014-11-20 15:00:51
,因为jquery不支持隐藏元素的位置,所以必须显示和定位.。
$('.settings-icon').click(function(){
$('#control-panel').show().position({
of: $(this),
my: 'left top',
at: 'left top'
});
});https://stackoverflow.com/questions/15647468
复制相似问题