0

When we want to inspect the event of scroll to bottom in browser in jquery. So we may write:

if $(window).scrollTop > $(document).height - $(window).height - 50 doScrollEvent(); //Event we do to load data when scroll to the bottom

So what's the difference between document and window here?

gongmingqm10
  • 27
  • 1
  • 7

3 Answers3

0

document refers to the width of the page itself. window refers to the viewport (i.e. how big your browser window is).

Machavity
  • 30,841
  • 27
  • 92
  • 100
0

The window object represents an open window in a browser. where as when an HTML document is loaded into a web browser, it becomes a document object. So there height and width may be different. One is a browser object and another is HTML dom object.

For more info look: http://www.w3schools.com/jsref/dom_obj_document.asp

and http://www.w3schools.com/jsref/obj_window.asp

Musfiqur rahman
  • 749
  • 4
  • 12
0

A quick search on Google, or here on StackOverflow, would have found a stack of answers. These will help you understand the difference.

  1. What is the difference between window, screen, and document in Javascript?

  2. trying to understand the difference between window and document objects in js

Community
  • 1
  • 1
TheCarver
  • 19,391
  • 25
  • 99
  • 149