I was trying to create twitter bootstrap submenu in dropdown menu, but I\'ve got a problem: I have dropdown menu in the top right corner of the page and that menu has one mo
I have created a javascript function that looks if he has enough space on the right side. If it has he will show it on the right side, else he will display it on the left side
Tested in:
Javascript:
$(document).ready(function(){
//little fix for the poisition.
var newPos = $(".fixed-menuprofile .dropdown-submenu").offset().left - $(this).width();
$(".fixed-menuprofile .dropdown-submenu").find('ul').offset({ "left": newPos });
$(".fixed-menu .dropdown-submenu").mouseover(function() {
var submenuPos = $(this).offset().left + 325;
var windowPos = $(window).width();
var oldPos = $(this).offset().left + $(this).width();
var newPos = $(this).offset().left - $(this).width();
if( submenuPos > windowPos ){
$(this).find('ul').offset({ "left": newPos });
} else {
$(this).find('ul').offset({ "left": oldPos });
}
});
});
because I don't want to add this fix on every menu items I created a new class on it. place the fixed-menu on the ul:
I hope this works out for you.
ps. little bug in safari and chrome, first hover will place it to mutch to the left will update this post if I fixed it.