1

我有一个 iframe,我想使用鼠标滚轮放大和缩小 iframe 内容,但目前我的主页在 iframe 内容滚动的同时滚动。

我想让我的主页在鼠标不在地图上时获得鼠标滚轮焦点,但在鼠标悬停时让地图(iframe)获得焦点:

http://digitouchmedia.com/digiMaps.html

这可能吗?

4

1 回答 1

1

First, you need access to the iframe's window object. This is only allowable if your iframe obeys the same origin policy.

Provided that you are on the same origin, you can access the IFrame window:

window.frames['nameOfYourIFrame'].focus();

To do this when you mouse over the iframe, I would consider nesting the iframe in a DIV element that has a body big enough to provide a "border" that can be used for detecting mouse enter and mouse exit. Attach the focus code above to this event handler.

NOTE: if the browser window is not active and in focus, I don't believe mouse events will occur. I could be mistaken.

于 2012-11-07T20:41:36.007 回答