'window.screenX' 值是否等于 $canvas.getBoundingClientRect().left?
Is 'window.screenX' value is equal to $canvas.getBoundingClientRect().left?
两者都是屏幕到 window 的水平距离,还是我这里完全错了?
我不是很清楚你说的 $canvas
是什么意思,但正如 here (MDN) 所说 Element.getBoundingClientRect()
:
The Element.getBoundingClientRect() method returns a DOMRect object
providing information about the size of an element and its position
relative to the viewport.
关于 viewport
here (MDN):
A viewport represents a polygonal (normally rectangular) area in
computer graphics that is currently being viewed. In web browser
terms, it refers to the part of the document you're viewing which is
currently visible in its window (or the screen, if the document is
being viewed in full screen mode). Content outside the viewport is not
visible onscreen until scrolled into view.
和here(MDN)关于Window.screenX()
The Window.screenX read-only property returns the horizontal distance,
in CSS pixels, of the left border of the user's browser viewport to
the left side of the screen.
所以你的问题的答案是否定的。它们是不同的。第一个是相对于浏览器 window 而第二个是相对于屏幕。如果浏览器 运行 处于全屏模式,它们可能匹配相同的值。
两者都是屏幕到 window 的水平距离,还是我这里完全错了?
我不是很清楚你说的 $canvas
是什么意思,但正如 here (MDN) 所说 Element.getBoundingClientRect()
:
The Element.getBoundingClientRect() method returns a DOMRect object providing information about the size of an element and its position relative to the viewport.
关于 viewport
here (MDN):
A viewport represents a polygonal (normally rectangular) area in computer graphics that is currently being viewed. In web browser terms, it refers to the part of the document you're viewing which is currently visible in its window (or the screen, if the document is being viewed in full screen mode). Content outside the viewport is not visible onscreen until scrolled into view.
和here(MDN)关于Window.screenX()
The Window.screenX read-only property returns the horizontal distance, in CSS pixels, of the left border of the user's browser viewport to the left side of the screen.
所以你的问题的答案是否定的。它们是不同的。第一个是相对于浏览器 window 而第二个是相对于屏幕。如果浏览器 运行 处于全屏模式,它们可能匹配相同的值。