0

我使用下面的 js 在我的网站上显示菜单,它工作正常,除了当浏览器窗口很小时下拉显示向上?我怎样才能使这个 JS 无论窗口大小如何,下拉菜单都会向下显示?

我试图在代码末尾设置 y=0,但没有运气。

var flexdropdownmenu = {
    arrowpath: '../Uploadedfiles/System/Scripts/flexdropdown/arrow.gif', //full URL or path to arrow image
    animspeed: 200, //reveal animation speed (in milliseconds)
    showhidedelay: [150, 150], //delay before menu appears and disappears when mouse rolls over it, in milliseconds

    //***** NO NEED TO EDIT BEYOND HERE
    startzindex: 1000,
    ismobile: navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)|(android)|(webOS)/i) != null, //boolean check for popular mobile browsers
    builtflexmenuids: [], //ids of flex menus already built (to prevent repeated building of same flex menu)

    positionul: function ($, $ul, e, $anchor) {
        var istoplevel = $ul.hasClass('jqflexmenu') //Bool indicating whether $ul is top level flex menu DIV
        var docrightedge = $(document).scrollLeft() + $(window).width() - 40 //40 is to account for shadows in FF
        var docbottomedge = $(document).scrollTop() + $(window).height() - 40
        if (istoplevel) { //if main flex menu DIV
            var offsets = $anchor.offset()
            var anchorsetting = $anchor.data('setting')
            var x = offsets.left + anchorsetting.useroffsets[0] + (anchorsetting.dir == "h" ? $anchor.outerWidth() : 0) //x pos of main flex menu UL
            var y = offsets.top + anchorsetting.useroffsets[1] + (anchorsetting.dir == "h" ? 0 : $anchor.outerHeight())
            x = (x + $ul.data('dimensions').w > docrightedge) ? x - (anchorsetting.useroffsets[0] * 2) - $ul.data('dimensions').w + $anchor.outerWidth() + (anchorsetting.dir == "h" ? -($anchor.outerWidth() * 2) : 0) : x //if not enough horizontal room to the ridge of the cursor
            y = (y + $ul.data('dimensions').h > docbottomedge) ? y - (anchorsetting.useroffsets[1] * 2) - $ul.data('dimensions').h - $anchor.outerHeight() + (anchorsetting.dir == "h" ? ($anchor.outerHeight() * 2) : 0) : y
            y = y - 5;
        }
        else { //if sub level flex menu UL
            var $parentli = $ul.data('$parentliref')
            var parentlioffset = $parentli.offset()
            var x = $ul.data('dimensions').parentliw //x pos of sub UL
            var y = 0
            x = (parentlioffset.left + x + $ul.data('dimensions').w > docrightedge) ? x - $ul.data('dimensions').parentliw - $ul.data('dimensions').w : x //if not enough horizontal room to the ridge parent LI
            y = (parentlioffset.top + $ul.data('dimensions').h > docbottomedge) ? y - $ul.data('dimensions').h + $ul.data('dimensions').parentlih : y
            //To show the submenu downwards irrespective of the browser resolution or size
            y = 0;
        }

        $ul.css({ left: x, top: y })
    }
4

1 回答 1

0
    if (istoplevel){ //if main flex menu DIV
        var offsets=$anchor.offset()
        var anchorsetting=$anchor.data('setting')
        var x=offsets.left+anchorsetting.useroffsets[0]+(anchorsetting.dir=="h"? $anchor.outerWidth() : 0) //x pos of main flex menu UL
        var y=offsets.top+anchorsetting.useroffsets[1]+(anchorsetting.dir=="h"? 0 : $anchor.outerHeight())
        x=(x+$ul.data('dimensions').w > docrightedge)? x-(anchorsetting.useroffsets[0]*2)-$ul.data('dimensions').w+$anchor.outerWidth()+(anchorsetting.dir=="h"? -($anchor.outerWidth()*2) : 0) : x //if not enough horizontal room to the ridge of the cursor
        //y=(y+$ul.data('dimensions').h > docbottomedge)? y-(anchorsetting.useroffsets[1]*2)-$ul.data('dimensions').h-$anchor.outerHeight()+(anchorsetting.dir=="h"? ($anchor.outerHeight()*2) : 0) : y
    }
    else{ //if sub level flex menu UL
        var $parentli=$ul.data('$parentliref')
        var parentlioffset=$parentli.offset()
        var x=$ul.data('dimensions').parentliw //x pos of sub UL
        var y=0
        x=(parentlioffset.left+x+$ul.data('dimensions').w > docrightedge)? x-$ul.data('dimensions').parentliw-$ul.data('dimensions').w : x //if not enough horizontal room to the ridge parent LI
        //y=(parentlioffset.top+$ul.data('dimensions').h > docbottomedge)? y-$ul.data('dimensions').h+$ul.data('dimensions').parentlih : y
    }
于 2013-06-15T08:35:41.090 回答