I've got a JQuery menu which I need to always stay visible on the screen at all times. So if the child menu would overlap the bottom of the window it should shift "up".
e.g.
It seems to work fine for smaller menus (e.g 5 items or less), but weirdly bigger ones seem to never shift up.
jsfiddle example- compare Menu Items C>1E to C>1F (You might need to resize your window so that they actually overlap the bottom)
i.e.
HTML:
<div id="container" style="width: 250px;">
<ul id="filter-menu-button-menu">
<li><a href="#"><span class="ui-icon ui-icon-disk"></span>A</a></li>
<li><a href="#"><span class="ui-icon ui-icon-disk"></span>B</a></li>
<li><a href="#"><span class="ui-icon ui-icon-folder-open"></span>C</a>
<ul>
<li><a href="#">1A</a></li>
<li><a href="#">1B</a></li>
<li><a href="#">1C</a></li>
<li><a href="#">1D</a></li>
<li><a href="#">1E</a>
<ul>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">1</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">2</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">3</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">4</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">5</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">6</a></li>
</ul>
</li>
<li><a href="#">1F</a>
<ul>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">1</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">2</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">3</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">4</a></li>
<li><span class="ui-icon ui-icon-trash"></span><a href="#">5</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
CSS:
$('#filter-menu-button-menu').menu({
"position": { my: "right top", at: "left top" }
});
Can anyone suggest why this is happening? Is it a bug in JQuery UI? Can anyone suggest a workaround?
You may want to check out the collision options for .position()
$('#filter-menu-button-menu').menu({
"position": {
my: "right top",
at: "left top",
collision: 'flipfit'
}
});
"flipfit": First applies the flip logic, placing the element on whichever side allows more of the element to be visible. Then the fit logic is applied to ensure as much of the element is visible as possible.