如果文档高于视口,则执行函数 [英] Execute function if document is taller than viewport
本文介绍了如果文档高于视口,则执行函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我经历的一些非常奇怪的行为。我想只在文档高于视口时执行一个函数(即它溢出它并出现一个滚动条)。我使用这段代码:
This is some quite strange behaviour I experience. I want to execute a function only when the document is taller than the viewport (i.e. it overflows it and a scrollbar appears). I use this code:
var docH = $("document").height(),
viewPortH = $("window").height();
if (docH > viewPortH) {
// execute functions
}
但没有任何反应并且控制台返回:
But nothing happens and console returns:
未捕获的TypeError:无法读取null的属性'parent'
Uncaught TypeError: Cannot read property 'parent' of null
有谁知道问题是什么/我应该使用什么代码来查看文档是否比视口高?
Does anyone know what the problem is/what code I should use to see whether the document is taller than the viewport?
推荐答案
文件
和窗口
是对象不是选择器。
document
and window
are objects not selectors.
var docH = $(document).height(),
viewPortH = $(window).height();
这篇关于如果文档高于视口,则执行函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文