基于鼠标位置的滚动将点击事件保留在前台

Scrolling based on mouse position retaining click events in the foreground

本文关键字:事件 保留 前台 滚动 于鼠标 鼠标 位置      更新时间:2023-09-26

所以我在一个较小的div中有一个非常宽的div。内部div 根据鼠标位置左右滚动。

我从这个答案中改编了代码...https://stackoverflow.com/a/6137535/3656408

所有东西的顶部有两个透明的div,从中获得鼠标的位置,从而提供滚动的速度。

这样做的问题是这些div 下面的任何东西都不可点击。

我的div具有固定的宽度和高度,因此我可能会从鼠标在页面上的位置计算滚动速度(即页面宽度为620px,因此我知道310是一半)

不幸的是,我的

数学很糟糕,我不知道如何将我的思维过程转换为可接受的工作代码。

有人有什么建议吗?

以下是它目前如何计算移动页面的速度......

$('.direction', backdrop).mousemove(function(e){
var $this = $(this);
var left = $this.is('.left');
if (left){
    var w = $this.width();
    rate = (w - e.pageX - $(this).offset().left + 1)/w;
}
else{
    var w = $this.width();
    rate = -(e.pageX - $(this).offset().left + 1)/w;
}
});

.. 你可以在这里看到它的实际应用 http://thetally.efinancialnews.com/tallyassets/20years/index.html

好吧,我想通了...

$( document ).mousemove(function(e){   //if mouse moves on page
if (e.pageX <= 620 && e.pageY <= 600){  //and if its not outside the extents of the div
    if (e.pageX <= 310){ //if its less than half way across
        rate = (310 - e.pageX)/50;
    } else { // if its more than half way across
        rate = -( e.pageX - 310)/50; 
    }
}
});