


Var y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? : Var x = supportPageOffset ? window.pageXOffset : isCSS1Compat ? : Var isCSS1Compat = ((patMode || "") = "CSS1Compat") A fully compatible example: var supportPageOffset = window.pageXOffset != undefined Additionally, older versions of Internet Explorer (< 9) do not support either property and must be worked around by checking other non-standard properties. The pageYOffset property is an alias for the scrollY property: window.pageYOffset = window.scrollY // always trueįor cross-browser compatibility, use window.pageYOffset instead of window.scrollY. Use this property to check that the document hasn't already been scrolled some if you are using relative scroll functions such as window.scrollBy, window.scrollByLines, or window.scrollByPages. Window.scroll(0, 0) // reset the scroll position to the top left of the document.
#Window screenx screeny scrollx scrolly code
These work in exactly the same way as screenX/ screenY.Īlso in the code we include a snippet that detects whether screenLeft is supported, and if not, polyfills in screenLeft/ screenTop using screenX/ screenY. Window.requestAnimationFrame(positionElem) PElem.textContent = 'Window.screenLeft: ' + window.screenLeft + ', Window.screenTop: ' + window.screenTop You can get the number of pixels the document is scrolled horizontally from the scrollX property. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number. Let newTop = window.screenTop + canvasElem.offsetTop Ĭtx.arc(leftUpdate + (width/2), topUpdate + (height/2) + 35, 50, degToRad(0), degToRad(360), false) The read-only scrollY property of the Window interface returns the number of pixels that the document is currently scrolled vertically.

Let newLeft = window.screenLeft + canvasElem.offsetLeft InitialTop = window.screenTop + canvasElem.offsetTop prompter, screen, screenX, screenY, scrollbars, scrollMaxX, scrollMaxY, scrollX, scrollY, sel, status, statusbar, textZoom, toolbar, top, window. initialLeft = window.screenLeft + canvasElem.offsetLeft
#Window screenx screeny scrollx scrolly plus
In this example we are using Window.screenLeft/ Window.screenTop plus Window.requestAnimationFrame() to constantly redraw the circle in the same physical position on the screen, even if the window position is moved. In our screenleft-screentop example, you'll see a canvas onto which has been drawn a circle.

Syntax topWindowPos = window.screenYĪ number equal to the number of CSS pixels from the top edge of the browser viewport to the top edge of the screen. This was originally supported only in IE but was introduced everywhere due to popularity. Esto es til, por ejemplo, en scripts que solo pueden detectar la position 'absoluta' de. window.scrollY y window.scrollX se utilizan para decidir cunto ha desplazado el usuario del website vertical u horizontalmente. Note: An alias of screenY was implemented across modern browsers in more recent times - Window.screenTop. Tratar de responder usando mi sentido comn, nada oficial, lo siento mucho si eso no es lo que quiso decir en su pregunta.
