使用 jQuery fadeIn 和 fadeOut 的 Google Maps API V3 InfoBox
我在网上到处搜索,但找不到使用 jQuery 淡出 Google 地图中的 InfoBox/InfoWindow 的教程或示例,而不是实际框/窗口的内容。这是我的代码,我不确定我做错了什么,但有些东西似乎也不正确。
google.maps.event.addListener(marker, 'mouseover', function() {
ib.setContent(html);
ib.open(map, marker);
ib.setValues({type: "point", id: 2})
var idName = marker.get("id"); //I was trying to the id's of the elements here
var boxName = ib.get("id"); //to use in my jQuery
jQuery(idName ).mouseover(function() {
jQuery(boxName ).fadeIn('slow', function() {
// Animation complete
});
});
});
I have searched the web high and low and have not been able to find a tutorial or example of using jQuery to fade an InfoBox/InfoWindow in Google Maps not the content the actual box/window. Here is my code, I'm not sure what I'm doing wrong, but something also doesn't seem right.
google.maps.event.addListener(marker, 'mouseover', function() {
ib.setContent(html);
ib.open(map, marker);
ib.setValues({type: "point", id: 2})
var idName = marker.get("id"); //I was trying to the id's of the elements here
var boxName = ib.get("id"); //to use in my jQuery
jQuery(idName ).mouseover(function() {
jQuery(boxName ).fadeIn('slow', function() {
// Animation complete
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
实际上可以淡入信息框,您必须像这样重写 infobox.js 文件中的绘制函数
It is actually possible to fadein the infobox, you have to override the draw function in the infobox.js file like this
我尝试了类似的网站。这是我的代码。 (gm-api-v3)
i tried something similar for a website. here is my code. (gm-api-v3)
如果您重写绘制方法并应用淡入,即使您在地图中拖动或放大/缩小,动画也会播放。如果您不希望发生这种情况,可以在 domready 处理程序中应用淡入方法。在这种情况下,只有打开信息窗口时才会出现淡入淡出效果。
;
If you override the draw method and apply the fade in,the animation will be played even if you drag around or zoom in/out in the map.If you don't want that to happen,you could apply the fadeIn in the domready handler method.In that case the fade in effect will come only if you the infowindow is opened.
;
我正在使用带标签的谷歌实用程序库标记(http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.5/docs/examples.html)
使用jquery很容易在标签上。
I am using the google utility library marker with label (http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.1.5/docs/examples.html)
It is easy to use jquery on the labels.
fadeOut效果可以通过添加class和setTimeout来实现。让我解释一下。
例如:
当您添加 CSS 类时,并且在 css 转换结束后关闭信息框
和 CSS (sass)(.infoBox 是保留类)
The fadeOut effect can be achieved by adding class and setTimeout. Let me explain.
For example:
when you add CSS class, and, after end of css transition you close the info box
and CSS (sass) (.infoBox is reserved class)
我认为这是不可能的,因为谷歌不提供动画选项。
尝试获取 Dom 元素也不起作用。 ib 变量是 google.maps.InfoWindow 类,而不是 DOM 元素。由于没有公共接口来获取信息窗口的 DOM 元素,您将无法自己访问它。
如果您使用console.log(ib.get("id")),您将看到ID未定义。
I do not think this is possible because Google does not provide an animation option.
Trying to get the Dom element will not work either. The ib variable is an google.maps.InfoWindow class not a DOM element. Since there is no public interface to get the DOM element for the info window you will not be able to access this yourself.
If you use
console.log(ib.get("id"))
you will see that the ID is undefined.