我正在创建工具提示的动态定位,我先在jsfiddle上测试代码然后将我的代码放到我的网站上(在localhost上使用wordpress构建),在jsfiddle我的脚本是可行的但是当我把代码放到我的网站时,它不起作用(不是动态地在chrome上)因为$(window).height()的结果不同.您可以检查this fiddle并尝试鼠标进入链接(第一个链接),然后在控制台上查看日志,窗口高度的结果为wh:667但在我的网站窗口高度为wh:12024和wh:11970(可更改)
jQuery(document).ready(function ($) {
$('a[rel="bookmark"]').mouseenter(function () {
console.log($(window).height());
})
});
也用这个
jQuery(function($){
$(window).ready(function(){
console.log($(window).height());
});
$(window).on('resize',function(){
console.log($(window).height());
});
});
谷歌浏览器
jsfiddle:667
我的网站(wordpress):12024 – 多变的
Mozilla的
jsfiddle:602
我的网站:585
我敢肯定,我已经添加了strict doctype.
我找到了this explanation
$(window).height()
is the height of the viewport that shows the
website. (excluding your toolbars and status bar and stuff like this)
$(document).height()
is the height of your document shown in the
viewport. If it is higher than$(window).height()
you get the
scrollbars to scroll the document
我认为在我的网站上结果$(window).height()是滚动条在chrome上滚动文档(我的网站有一个很长的页面).如果是这样,我怎样才能在我的网站上获得视口的高度,是否有另一种方法可以获得每个浏览器(chrome,mozilla,opera等)视口的相同结果(实际)高度?