Hi Jesse and Joel,

I think the piece that you are missing, which is the cause of your problem, is the page (Y) offset. If there is a vertical scrollbar, you'll need the page y offset; with a horizontal scrollbar, the page x offset (IE has different names for these things). The dimensions plugin has a method for each of these: .scrollTop() and .scrollLeft(). You'll need to use them or something similar for your expandUp and expandLeft variables, respectively, and for the the "margin-left" and "margin-top" calculations.

Here is a horribly ugly, though concise, function that combines the two. It inappropriately uses the ternary operator for the sake of brevity, but as long as it's a private function, it probably won't do any harm. (it's embarrassing, really, but I just threw it together, so please don't laugh too hard.) If you spend some time cleaning it up, I'd love to see the result.

function offset(dir) {
  return window[dir == 'y' ? 'pageYOffset' : 'pageXOffset']
|| document.documentElement && document.documentElement[dir == 'y' ? 'scrollTop' : 'scrollLeft']
    || document.body[dir == 'y' ? 'scrollTop' : 'scrollLeft'];
}


Then, you can use it for those variables, for example:

  var expandUp = (offsetTop + menuHeight > windowHeight + offset('y'));

var expandLeft = ($u.offset().left + menuWidth > $w.width() + offset('x'));


The clueTip plugin does a lot of this sort of calculation to keep tooltips in the viewable area, so feel free to grab stuff from that, too, if you'd like.

Hope that helps.

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 31, 2008, at 3:10 AM, Jesse Klaasse wrote:


I am still struggling to find the time to work on those bugs. Anyone who has ideas about this, please feel free to contact me/Joel via this list.

Joel, I appreciate your work, sorry I hadn't answered yet!


-----Original Message-----
About the callbacks. Would they enable us to write for instance this
code outside of superfish ?
http://www.klaasse.net/superfish-ext/superfish.html

Yes. This is precisely the reason for the new callbacks. In fact I
rewrote Jesse Klaasse's code to use the callbacks and the demo page can
be found here:
http://users.tpg.com.au/j_birch/plugins/superfish/supposition-test/menuA
tTop.html

I gave it the plugin of the plugin the name "Supposition" which is the
crapiest name ever. Anyway, there are still issues with that code
because when the document is longer than the window depth the scrolling
is not taken into account when positioning the submenus which is
disappointing. I don't know if this is a jQuery bug or a problem with
the Supposition (hate that name so much) code as I am a n00b when it
comes to dimensions code. I flicked my work back to Jesse to look at and
also posted it to this group. Here's the thread:
http://groups.google.com/group/jquery-en/browse_thread/thread/c4a290fc6a
2f6bfd



Reply via email to