动态高度 jQuery
我正在使用 Google 地图 API 来拉回带有一系列点的地图。我还拉回了 ID="directionsPanel" 元素中显示的方向。这一切都很好,除了当我们超过一定数量的点(Firefox 中为 3,Chrome 中为 4)时,它们会溢出页面。
我使用以下 jQuery 代码来检测元素高度是多少(大概是在加载方向之后),然后进行相应调整:
$(document).ready(function() {
if($.browser.mozilla)
{
var sHeight = $("#directionsPanel").height();
sHeight = (sHeight * 1.5);
$("#directionsPanel").height(sHeight);
}
else
{
// do stuff for other browsers
}
});
不幸的是,元素没有调整到正确的高度(也许它没有检测到正确的初始高度? )并且事情仍然从页面上溢出。关于如何使其更加稳健有什么想法吗?
I am using the Google Maps API to pull back a map with a series of points on it. I am also pulling back directions which are displayed in the element with ID="directionsPanel". This is all well and good except for the fact that when we get past a certain number of points (3 in Firefox, 4 in Chrome) they spill off the page.
I am using the following jQuery code to detect what the element height is (presumably after the directions are loaded) and then adjust it accordingly:
$(document).ready(function() {
if($.browser.mozilla)
{
var sHeight = $("#directionsPanel").height();
sHeight = (sHeight * 1.5);
$("#directionsPanel").height(sHeight);
}
else
{
// do stuff for other browsers
}
});
Unfortunately the element is not being adjusted to the right amount (perhaps it is not detecting the correct initial height?) and things are still spilling off the page. Any thoughts on how I might make this more robust?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google Maps API 可能允许您指定地图加载时的回调函数,这就是您应该放置代码的位置。
例如:
不要使用
$(document).ready()
因为它会在 DOM 加载时立即执行。Google Maps API probably lets you specify a callback function for when the map has loaded, and that is where you should put your code.
For example:
Don't use
$(document).ready()
since that executes immediately when the DOM is loaded.