Get the offset position of an HTML5 range slider handle

后端 未结 4 1105
一生所求
一生所求 2021-01-06 06:51

Is there any way to get the pixel position of the slider handle of an HTML5 range input ?



        
4条回答
  •  难免孤独
    2021-01-06 07:19

    This worked for me:

    var slider = $("#combicalc_contribution-slider")[0];
    var sliderPos = slider.value / slider.max;
    
    var pixelPostion = slider.clientWidth * sliderPos;
    //this is your pixel value
    console.log(pixelPostion);
    

    The pixel value was calculated properly for values from 1 to 50, on your example.

提交回复
热议问题