gets the absolute x, y coordinates of an element of the page, which can be used with the offset () method: var X = $ (' #DivID '). Offset (). Top;var Y = $ (' #DivID '). Offset (). Left; get relative (parent element) Position: var X = $ (' #DivID '). Position (). Top;var Y = $ (' #DivID '). Position (). Left; let div move with scroll bar:<DivID= "Olayer"style= "position:absolute; left:0; top:80px; z-index:2; background:a9c9ef; margin-left:6px; width:140px; height:70px "></Div>jquery Code: $ (window). Scroll (function () {var init_pos = $ (' #oLayer '). O Ffset (). Top; $ (' #oLayer '). CSS ("Top", $ (window). scrolltop () +80)});
$ (document). Bind (' MouseMove ', function (e) {var x = E.pagex;var y = e.pagey; });
Gets the height of the browser display area (viewable area): $ (window). Height (); Gets the width of the browser display area (viewable area): $ (window). width (); Gets the document height of the page. Height (); Gets the document width of the page: $ (documents). width ();the height of the body of the browser's current window document:$ (document.body). Height (), browser current window document body width: $ (document.body). width (); Gets the vertical height of the scroll bar to the top (that is, the height of the page being rolled up) $ (document). ScrollTop (); Gets the vertical width of the scroll bar to the left: $ (document). ScrollLeft (); Gets or sets the width of the element: $ (obj). width (); Gets or sets the height of the element: $ (obj). height (); The distance from the upper boundary of an element to the top of the body: Obj.offset (). Top; (in the case that the element contains no scroll bars) the left edge of an element to the leftmost distance of the body: Obj.offset (). (in the case that the element contains no scroll bars) returns the upper boundary of the current element to its offset of the upper boundary of the containing element: Obj.offset (). Top (in the case where the element's containing element contains a scrollbar) returns the offset of the left edge of the current element to its containing element: Obj.offset (). Left (with scroll bars in the element's containing element)
- ScrollTop (), ScrollLeft ()
- Sets or returns the number of pixels that have scrolled to the left or upper bounds of an element. To put it simply, it is to set or get the offset of the matching element relative to the top or left side of the scroll bar. These pixels are useful only when the element has a scrollbar, for example, when the element's CSS overflow property is set to Auto. These properties are also defined only on the <body> or
jquery get element coordinates get mouse coordinates