AutoHide does not work properly when the trigger object is affixed on screen. #95

Closed
alickq opened this Issue Dec 12, 2012 · 1 comment

Comments

Projects
None yet
2 participants

alickq commented Dec 12, 2012

I have created a web site that has a tree object on the left hand side and some content on the right. I fixed the position of the tree so that when the window scroll, the tree stays. When I ture on the AutoHide feature, it does not recognize the fact that I am still inside the trigger object when I move my mouse so the menu disappear as soon as I move my mouse to the left just by a tiny little bit. I have looked at the source code and found that you are using .position() function to get the position of the menu. If I change it to use .offset() instead, it all worked fine. I am wondering if there is a reason why you use .position() over .offset()? Here is the code segment:

        if (opt.autoHide) {
            // trigger element coordinates

// var pos = $this.position();

            // change to use .offset instead as .position returns position relative to offset parent where offset is relative to 
            //       the page or document.  It will not work if the triggering object has a fix position if we use .position.
            var pos = $this.offset();
            pos.right = pos.left + $this.outerWidth();
            pos.bottom = pos.top + this.outerHeight();
            // mouse position handler
            $(document).on('mousemove.contextMenuAutoHide', function(e) {
                if (opt.$layer && !opt.hovering && (!(e.pageX >= pos.left && e.pageX <= pos.right) || !(e.pageY >= pos.top && e.pageY <= pos.bottom))) {
                    // if mouse in menu...
                    opt.$menu.trigger('contextmenu:hide');
                }
            });
        }
Contributor

rodneyrehm commented Dec 13, 2012

I'll look into this around christmas. The jQuery.offset() hunch is confirmed.

rodneyrehm closed this Dec 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment