在AngularJS中获取滚动事件的鼠标位置

时间:2015-01-13 16:34:24

标签: angularjs

我可以在滚动事件中获得鼠标位置吗?

如果我有代码:

    angular.element($window).bind("scroll", function() {
        console.log("scroll");
        // mouse position (x,y) ?
    });

2 个答案:

答案 0 :(得分:0)

angular.element($window).bind("scroll", function(event) {
    console.log("scroll");
    console.log(event.clientX, event.clientY); //relative to window
    console.log(event.pageX, event.pageY); //relative to window
});

答案 1 :(得分:0)

您可以使用

angular.element($window).bind("scroll", function(event) {
   console.log("scroll");
   var domElem = event.target;

   var nbPXFromTop = domElem.scrollTop; //nb of pixel from the top 
   var nbPxFromLeft = domElem.scrollLeft;
});