从js文件调用thickbox
您好,我正在尝试将厚框添加到谷歌地图中的叠加层中。 在我的 JQuery onload 函数中,我调用以下函数。 地图工作正常。 但当厚盒子似乎没有被调用时。 这是行得通的行
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>
整个函数
function load(lat, lng, zlevel, userKey, state) {
map = new GMap2(document.getElementById("map"));
map.disableDoubleClickZoom();
map.setCenter(new GLatLng(lat, lng), zlevel);
if (state) {
dsp = true;
map.addControl(new GLargeMapControl());
GEvent.addListener(map, "click", function(overlay, latlng) {
var zoom = map.getZoom();
var display = '<h5 class="header-flag">Flag</h5><p class="maptext"><a href="#" onclick="javascript:openOverlay(' + latlng.lat() + ',' + latlng.lng() + ',' + zoom + ');">Click here</a> to enter your comment -
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a></p>';
setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); }, 0);
});
} else {
}
mgr = new MarkerManager(map);
loadMarkers(userKey);
mgr.refresh();
}
Hi i am trying to add thick box to a overlay in googlemaps. On my JQuery onload function i call the following function. The map works fine. But when the thick box doesn't seem to be called. This is the line that does work
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a>
The whole function
function load(lat, lng, zlevel, userKey, state) {
map = new GMap2(document.getElementById("map"));
map.disableDoubleClickZoom();
map.setCenter(new GLatLng(lat, lng), zlevel);
if (state) {
dsp = true;
map.addControl(new GLargeMapControl());
GEvent.addListener(map, "click", function(overlay, latlng) {
var zoom = map.getZoom();
var display = '<h5 class="header-flag">Flag</h5><p class="maptext"><a href="#" onclick="javascript:openOverlay(' + latlng.lat() + ',' + latlng.lng() + ',' + zoom + ');">Click here</a> to enter your comment -
<a href="test.html?keepThis=true&TB_iframe=true&height=250&width=400" title="add a caption to title attribute / or leave blank" class="thickbox">Example 1</a></p>';
setTimeout(function() { map.openInfoWindowHtml(latlng, display, { maxWidth: 200 }); }, 0);
});
} else {
}
mgr = new MarkerManager(map);
loadMarkers(userKey);
mgr.refresh();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调用 Thickbox 函数后,将要激活 Thickbox 的链接添加到 DOM。 这是因为您正在 map.openInfoWindowHtml 函数中动态创建链接。 执行完该函数后,您需要调用该函数。
问题是我刚刚查看了thickbox文档,一旦DOM加载,thickbox就会在thickbox.js文件中设置,这对你来说太快了。 您可以尝试将 setTimeout 函数更改为:
我不能 100% 确定这会起作用,但这是问题的关键。
Your adding the link that you want to activate the thickbox to the DOM after the thickbox function has already been called. This is because you are creating the link dynamically within the map.openInfoWindowHtml function. You need to call the thickbox function after this function has been executed.
Trouble is I just looked at the thickbox docs and thickbox gets set up within the thickbox.js file as soon as the DOM loads which is too soon for you. You could try to alter the setTimeout function to this:
I cant be 100% sure this will work, but this is the crux of the problem.