[英]Facebook like popover setting menu jquery and css
I am preparing a menu facebook style. 我正在准备一个菜单Facebook风格。 I encode is running smoothly.
我编码运行顺利。 But when I click the drop-down menu remains open in other userposts.
但是,当我单击下拉菜单时,在其他用户帖子中仍保持打开状态。 I want to get a diverse menu of each post.
我想获得每个帖子的多样化菜单。 not associated with each other.
彼此不相关。 What do I need it to be?
我需要什么?
This is demo jsfiddle 这是演示jsfiddle
HTML CODE: HTML代码:
<div class="container">
<div class="pay_ayar">
<a class="account"></a>
<div class="bubble">
<ul class="root">
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<div class="pay_ayar">
<a class="account"></a>
<div class="bubble">
<ul class="root">
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
<li><a href="#">Link2</a></li>
</ul>
</div>
</div>
</div>
CSS code: CSS代码:
.container {
float:left;
width:500px;
height:90px;
border:1px solid #000;
margin-top:30px;
}
.pay_ayar {
float:right;
width:20px;
height:25px;
border:1px solid #000;
display:none;
}
.container:hover .pay_ayar{
display:block;
}
a.account{
position:absolute;
line-height:25px;
width:20px;
height:25px;
cursor:pointer;
display:block;
}
.bubble{
float:left;
position:relative;
width:250px;
height:200px;
padding:0px;
border:1px solid #000;
margin-top:0px;
display:none;
margin-left:-230px;
top:25px;
}
.pay_ayar.open .account {
cursor: pointer;
width: 20px;
height:25px;
display: inline-block;
border: 1px solid #AAA;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
font-weight: bold;
color: #717780;
line-height: 16px;
text-decoration: none !important;
background: white url("http://ttb.li/dump/buttons/dropdown_arrow.png") no-repeat 100% 0px;
}
.pay_ayar.open .account {
border: 1px solid #3B5998;
color: white;
background: #6D84B4 url("http://ttb.li/dump/buttons/dropdown_arrow.png") no-repeat 100% -26px;
-moz-border-radius-topleft: 2px;
-moz-border-radius-topright: 2px;
-moz-border-radius-bottomright: 0px;
-moz-border-radius-bottomleft: 0px;
-webkit-border-radius: 2px 2px 0px 0px;
border-radius: 2px 2px 0px 0px;
border-bottom-color: #6D84B4;
}
and Javascript code : 和Javascript代码 :
$(document).ready(function()
{
$(".account").click(function()
{
if($(".bubble").css('display')=='none')
{
$(".pay_ayar").addClass('open');
$(".bubble").css('display','block');
}
else
{
$(".bubble").css('display','none');
$(".pay_ayar").removeClass('open');
}
});
$(document).click(function(e)
{
if($(e.target).attr('class')!='account')
{
if($(".bubble").css('display')=='block')
{
if($('.pay_ayar').hasClass('open'))
{
$('.pay_ayar').removeClass('open');
}
$(".bubble").css('display','none');
}
}
});
});
You have to get the current user target. 您必须获取当前的用户目标。 You can get this with the user click event: http://jsfiddle.net/pu7NQ/13/
您可以通过用户点击事件获得此信息: http : //jsfiddle.net/pu7NQ/13/
$(".account").click(function(event)
{
var $container = $(event.target).closest(".container");
if($(".bubble", $container).css('display')=='none')
{
$(".pay_ayar", $container).addClass('open');
$(".bubble", $container).css('display','block');
}
else
{
$(".bubble", $container).css('display','none');
$(".pay_ayar", $container).removeClass('open');
}
});
This sure could be more elegant, but you get the idea. 这肯定会更优雅,但是您明白了。
If you want to close one element, on click outside, you will have to add a event listener to the document and listen, if the event was outside of the desired element. 如果要关闭一个元素,请单击外部,如果该事件在所需元素之外,则必须向该文档添加一个事件侦听器并进行侦听。 There is a plugin for that: http://benalman.com/projects/jquery-outside-events-plugin/
有一个用于该插件: http : //benalman.com/projects/jquery-outside-events-plugin/
// add close listener
$container.on("clickoutside.outside",function(){
$(".pay_ayar").removeClass("open");
$(".bubble").hide();
$(this).off("clickoutside.outside");
});
Demo: http://jsfiddle.net/pu7NQ/16/ 演示: http : //jsfiddle.net/pu7NQ/16/
You should really consider, adding a close/open function to get rid of the code duplication. 您应该真正考虑,添加一个关闭/打开函数来消除代码重复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.