What is the difference between screenX/Y, clientX/Y and pageX/Y?

后端 未结 7 1480
夕颜
夕颜 2020-11-22 13:38

What is the difference between screenX/Y, clientX/Y and pageX/Y?

Also for iPad Safari,

7条回答
  •  梦谈多话
    2020-11-22 14:03

    What helped me was to add an event directly to this page and click around for myself! Open up your console in developer tools/Firebug etc and paste this:

    document.addEventListener('click', function(e) {
      console.log(
        'page: ' + e.pageX + ',' + e.pageY,
        'client: ' + e.clientX + ',' + e.clientY,
        'screen: ' + e.screenX + ',' + e.screenY)
    }, false);
    Click anywhere

    With this snippet, you can track your click position as you scroll, move the browser window, etc.

    Notice that pageX/Y and clientX/Y are the same when you're scrolled all the way to the top!

提交回复
热议问题