3レベルのメニューがあります。サブメニューを表示するのに十分な画面スペースがない場合、サブメニューを右ではなく左方向に開くようにします。
正確なアイデアを得るために、スクリーンショットを見てください。
これを修正するために superfish メニューの onBeforeShow() 関数を使用したいのですが、思い通りに動作させることができません。
これまでの私のコードは次のとおりです。
$("ul.sf-menu").superfish({
delay: 1000,
speed: 'fast',
disableHI: true,
onBeforeShow: function()
{
thisWidth = $(this).width();
if ( thisWidth > 0 )
{
thisParent = this.parent();
parentLeft = thisParent.offset().left;
parentWidth = this.parent().width();
parentRight = parentWidth + parentLeft ;
mainLeft = document
.getElementsByClassName('sf-menu')[0].offsetLeft;
mainRight = document
.getElementsByClassName('sf-menu')[0].offsetWidth;
if ( ( thisWidth + parentLeft ) < ( mainLeft + mainRight ) )
{
if ( thisWidth > ( parentLeft + parentHeight ) )
{
$(this).css('left', - (parentLeft - mainLeft));
}
else
{
// open left
$(this).css('left', - (thisWidth - parentWidth));
}
}
}
}
});