wordpress上的$(window).height()太多了 [英] Too big number of $(window).height() on wordpress
问题描述
我正在创建工具提示的动态定位,我先在jsfiddle上测试代码然后将我的代码放到我的网站上(在localhost上使用wordpress构建),在jsfiddle上我的脚本是可行的但是当我把代码放到我的网站上时,它是因为 $(窗口).height()
的结果不同,所以不起作用(不是动态地在chrome上)。您可以查看这个小提琴并尝试鼠标进入链接(第一个链接),然后查看日志在控制台,窗口高度的结果是 wh:667
但在我的网站窗口高度是 wh:12024
和 wh:11970
(可更改)
I'm creating dynamic posisition of tooltip, I have tested code on jsfiddle first before put my code to my site (build with wordpress on localhost), on jsfiddle my script is works but when I put code to my site, It's not works (not dynamically on chrome) because different result of $(window).height()
. You can check this fiddle and try to mouse enter to a link (first link) and then see log at console, the result of window height is wh :667
but on my site window height is wh :12024
and wh : 11970
(changeable)
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
jsfiddle : 667
我的网站(wordpress):12024 - 可更改
my site (wordpress) : 12024 - changeable
Mozilla
jsfiddle:602
jsfiddle : 602
我的网站:585
我确定,我已经添加了严格的doctype 。
I'm sure, I have added strict doctype.
我发现此解释
$(窗口).height()
是显示
网站的视口高度。 (不包括你的工具栏和状态栏以及类似的东西)
$(window).height()
is the height of the viewport that shows the website. (excluding your toolbars and status bar and stuff like this)
$(文件).height()
是
视口中显示的文档高度。如果它高于 $(窗口)。高度()
你得到
滚动条来滚动文档
$(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
我认为我的网站结果 $(窗口).height()
是滚动条以滚动 chrome <上的文档/ strong>(我的网站有很长的页面)。如果是这样,我怎样才能在我的网站上获得视口的高度,是否有另一种方法可以获得每个浏览器(chrome,mozilla,opera等)视口的相同结果(实际)高度?
I think on my site result $(window).height()
is scrollbars to scroll the document on chrome (fyi my site have a long page). If it is like that, how can I get height of the viewport on my site, is there another way to get same result (actual) height of the viewport every browser (chrome, mozilla, opera etc) ?
注意:我不认为使用 screen.height
因为它可以显示屏幕(包括浏览器的工具栏)
note : I don't think for use screen.height
because it can result display of screen (include toolbar of browser)
推荐答案
调试这个宝宝花了我几个小时/天,但我终于明白了。信不信由你,但我没有这样的错误!多么讨厌的bug。
It took me hours/days to debug this baby, but I finally got it. Believe or not, but I haven't had such bug for YEARS!! What a nasty bug.
我不是说你有确切的问题,但是,这个线程正是我所面对的。我100%确定我的html设置为严格。
I am not saying you had the exact problem, however, this thread is exactly what I was facing. I was 100% sure that my html is set to strict.
但是,只要我在Chrome中执行检查元素,严格DOCTYPE的实际定义已经消失。所以我检查了其他网站,我立刻意识到有一些极端可疑的事情发生,这不应该发生。 谁吃了严格的doctype?
However, as soon as I did "Inspect element" in Chrome, the actual definition of strict DOCTYPE was gone. So I checked other websites, and I immediately realized that there is something extremly fishy going on, this shouldn't be happening. Who ate my strict doctype?
不仅如此,我注意到HEAD的内容已移至<身体>
和其他奇怪的事情正在发生。
Not only that, but I noticed that the contents of HEAD moved to <body>
and other weird things were happening.
我做了任何合理的人做的事情,我推测我所有的时间都浪费在这个愚蠢的UTF-8 BOM上,因为我在这方面遇到了很多问题。过去。哦,男孩,我是正确的。
I did what any reasonable human would do, I speculated that all my time was wasted on this stupid UTF-8 BOM, as I've had many problems with that in the past. Oh boy was I correct.
在我没有bom切换到UTF-8之后,一切都开始完美无缺。请注意,有趣的是:我的网站似乎100%工作,即使是混乱的HTML(我从未注意到浏览器的解释方式不正确)。
Everything started to work flawlessly, after I've switched to UTF-8 without bom. Notice that the interesting thing is: my website seemed to work 100%, even with messed up HTML(I never noticed that browser interpreted it way incorrectly).
为什么我的网站文件编码为UTF-8,首先是bom和&为什么它甚至会影响浏览器?我不知道。
Why was my file encoded as UTF-8 with bom at first place & why should it even affect browser? I have no idea.
这篇关于wordpress上的$(window).height()太多了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!