我正在使用jquery编写一个站点,它反复调用$(window).width()
和$(window).height()
来根据视口大小定位和调整元素的大小.
In troubleshooting I discovered that I am getting slightly different viewport size reports in repeated calls to the above jquery functions when the viewport is not resized.
想知道是否有任何特殊情况下,任何人都知道这种情况发生,或者如果这只是它的方式.据报道,大小的差异似乎是20px或更小.它发生在Mac OS X 10.6.2上的Safari 4.0.4、Firefox 3.6.2和Chrome 5.0.342.7测试版中.我还没有测试其他浏览器,因为它似乎不是特定于浏览器的.我也无法找出差异取决于什么,如果不是视口大小,是否还有其他因素导致结果不同?
如有任何见解,将不胜感激.
update:
It is not the values of $(window).width()
and $(window).height()
that are changing. It's the values of the variables I am using to store the values of the above.
影响值的不是滚动条,当变量值更改时不会出现滚动条.下面是我在变量中存储值的代码(我这样做只是为了让它们更短).
(这一切都在$(document).ready()
以内)
//initially declare the variables to be visible to otehr functions within .ready()
var windowWidth = $(window).width(); //retrieve current window width
var windowHeight = $(window).height(); //retrieve current window height
var documentWidth = $(document).width(); //retrieve current document width
var documentHeight = $(document).height(); //retrieve current document height
var vScrollPosition = $(document).scrollTop(); //retrieve the document scroll ToP position
var hScrollPosition = $(document).scrollLeft(); //retrieve the document scroll Left position
function onm_window_parameters(){ //called on viewer reload, screen resize or scroll
windowWidth = $(window).width(); //retrieve current window width
windowHeight = $(window).height(); //retrieve current window height
documentWidth = $(document).width(); //retrieve current document width
documentHeight = $(document).height(); //retrieve current document height
vScrollPosition = $(document).scrollTop(); //retrieve the document scroll ToP position
hScrollPosition = $(document).scrollLeft(); //retrieve the document scroll Left position
}; //end function onm_window_parameters()
I inserted an alert statement to probe the variables above against the values they are supposed to be holding. The $(item).param()
values stay consistent, but my variables change for reasons I can't figure out.
我一直在寻找我的代码可能会改变相关变量值的地方,而不是仅仅检索它们的设置值,却什么都找不到.如果有可能的话,我可以把整个shebang发到某个地方.