var getPosFormEle = (function(ele) { var x,y; var elex = ele.getBoundingClientRect().left; var eley = ele.getBoundingClientRect().top; var st = document.body.scrollTop; document.onScroll = function(){ st = document.body.scrollTop; // console.log(document.body.scrollTop) } return function(e) { x = Math.round(e.pageX - elex); y = Math.round(e.pageY - eley-st); // console.log('getPosFormCanvas,x:',x,', y:',y); return {x:x,y:y}; } })(ele);