Frames Example | Page 4 |
Positioning the menu is pretty simple. We want it to appear on the far left,
right next to the boundry between the two frames so the x-coordinate should be
zero.
However, the page in the right-hand frame may have been scrolled horizontally, so the function checks for that by calling the getPageScollX() function in the right-hand frame. It does this by referencing the frame on the call.
x = parent.frames[frameName].getPageScrollX(); This will give the x-coordinate of the first visible pixel on the left edge of that frame. For the y-coordinate, the same thing is done, except that the global variable mouseY is used to determine how far down the mouse pointer is from the top of the left-hand frame. This is then added to the vertical scroll offset of the right-hand frame to find the proper value. y = mouseY + parent.frames[frameName].getPageScrollY(); Then it's just a matter of opening the menu at the calculated coordinates. The last thing the function does is to update the lastMenu varible to point to the menu just opened. Then it can be closed before a opening a different menu the right-hand frame. Notes on the Example This final page does not contain any pop-up menus. Mousing over the menu links at left will not cause an error however, because the code in the left-hand frame checks to ensure that a menu exists before attempting to open it. Otherwise you would run into problems if any link on your site opened a page that did not have menus defined for it. This is especially important if you opened a page located on another web site. For security reasons, you cannot normally access or execute JavaScript code between frames when the pages are from different hosts. Also note that in this example, all the pages with menus use the same menu definitions. This is not necessary, you could have each page set up with its own set of menus. The important thing to remember is that the left-hand frame needs to have the correct variable name used for the menu in the right-hand frame, otherwise it won't be able to reference it. Source
Note that popcond.js will be extremely hard to read since all comments and spacing have been removed. But the code itself is just the contents of dhtmllib.js and popupmenu.js combined for faster download.
Prev |