检测用户点击的水平位置的百分比

Detect the percentage of the horizontal position that users click on

本文关键字:水平 百分比 位置 用户 检测      更新时间:2023-09-26

我正试图从头开始制作一个滑块,就像jQuery UI一样,但我不确定如何检测用户单击滑块的水平位置。

例如,如果我点击中间的foodiv,它将返回50%。如果有的话,我就很容易相应地调整滑块的填充div宽度。

试试这个:http://jsfiddle.net/UCFtB/1/

脚本:

$("#test").mousemove(function(e){
    var perc = e.offsetX/ $(this).width() * 100;
    $(this).html(e.offsetX + " | " + perc + " perc");
});