...然后向上滑动,但不仅仅是。重要!:如果意外点击,禁止关注子菜单的父链接。
下面与我想要达到的完全相似,区别在于:子菜单在点击时向下/向下滑动:
HTML:
let string = NSAttributedString(string: string, attributes: attributes)
let size = string.boundingRectWithSize(CGSizeMake(YOUR_WIDTH, CGFloat.max), options: .UsesLineFragmentOrigin, context: nil)
let height = size.height
的javascript:
<ul id="toggle">
<li> <a href="/">Home</a>
<li> <a href="/products">Products</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/products/potatos">Potatos</a></li>
<li><a href="/products/carrots">Carrots</a></li>
</ul> </li>
<li><a href="/contact">Contact</a>
<ul class="dropdown-menu" role="menu">
<li><a href="/contact/people">People</a></li>
<li><a href="/contact/map">Map</a></li>
</ul>
</li>
</ul>
答案 0 :(得分:1)
答案 1 :(得分:0)
可能是这样的吗?
$('#toggle li:has(.dropdown-menu)').hover(function (event) {
if ($(event.target).parents('.dropdown-menu').length > 0) {
event.stopPropagation();
} else {
event.preventDefault();
}
$(this).find('ul').slideToggle();
});
$('#toggle li:has(.dropdown-menu)').hover(function (event) {
if ($(event.target).parents('.dropdown-menu').length > 0) {
event.stopPropagation();
} else {
event.preventDefault();
}
$(this).find('ul').slideToggle();
});