Dropdown menu fixepar rapport à contenu
Bonjour,
je voudrais fixer dropdown menu suivant le contenu de la page et non pas par rapport à le boutton.
voila mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <div class="bs-example">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Default <span class="caret"></span></button><br><br>
ffff<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
ffff<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| .bs-example
{
margin: 30px;
height: 120px;
overflow: scroll;
}
.dropdown-menu{
position:fixed;
}
.button{
height:30px;
} |
Code:
1 2 3 4 5 6 7 8
| $('.dropdown-toggle').click(function (){
dropDownFixPosition($('button'),$('.dropdown-menu'));
});
function dropDownFixPosition(button,dropdown){
var dropDownTop = button.offset().top + button.outerHeight();
dropdown.css('top', dropDownTop + "px");
dropdown.css('left', button.offset().left + "px");
} |