click mouse position with scroll in javascript

前端 未结 3 641
感情败类
感情败类 2020-12-19 19:43

I have code to get x-y coordinates when the browser scrolls:

left1 = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
t         


        
3条回答
  •  感情败类
    2020-12-19 20:06

    The following JS works in IE 8 and firefox 3.6.17

    function getScrollingPosition()
    {
    var position = [0, 0];
    if (typeof window.pageYOffset != 'undefined')
    {
    position = [
    window.pageXOffset,
    window.pageYOffset
    ];
    }
    else if (typeof document.documentElement.scrollTop
    != 'undefined' && document.documentElement.scrollTop > 0)
    {
    position = [
    document.documentElement.scrollLeft,
    document.documentElement.scrollTop
    ];
    }
    else if (typeof document.body.scrollTop != 'undefined')
    {
    position = [
    document.body.scrollLeft,
    document.body.scrollTop
    ];
    }
    return position;
    }
    

    This article also may help. http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html

提交回复
热议问题