Edit (05.05.2010): If the window is scrolled (which is unlikely for a JS canvas application, but might happen in some cases) the method above will give wrong results. You'll have to adjust for the scroll with $(window).scrollTop() (or scrollLeft() for horizontal scrolling).