how to make twitter bootstrap submenu to open on the left side?

前端 未结 12 2137
余生分开走
余生分开走 2020-12-13 05:12

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

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 05:58

    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. Again if it has has enough space on the right side, it will show right side. it is a loop...

    $(document).ready(function () {
    
    $('body, html').css('overflow', 'hidden');
    var screenWidth = $(window).width();
    $('body, html').css('overflow', 'visible');
    
    if (screenWidth > 767) {
    
        $(".dropdown-submenu").hover(function () {
    
            var dropdownPosition = $(this).offset().left + $(this).width() + $(this).find('ul').width();
            var newPosition = $(this).offset().left - $(this).find('ul').width();
            var windowPosition = $(window).width();
    
            var oldPosition = $(this).offset().left + $(this).width();
            //document.title = dropdownPosition;
            if (dropdownPosition > windowPosition) {
                $(this).find('ul').offset({ "left": newPosition });
            } else {
                $(this).find('ul').offset({ "left": oldPosition });
            }
        });
    
    }
    

    });

提交回复
热议问题