Determine click position on progress bar?

前端 未结 8 1864
傲寒
傲寒 2021-02-08 19:38

Is it possible to determine the value/position of a user\'s click on a progress bar using plain javascript?

Currently, I can detect a click on the element but can only g

8条回答
  •  执笔经年
    2021-02-08 20:14

    The click event actually takes a parameter that includes event information including the click position information. You can use this to determine where in the progress bar the click occured.

    document.getElementById('progressBar').addEventListener('click', function (event) {
    
        document.getElementById('result').innerHTML = ('Current position: ' + document.getElementById('progressBar').position + "
    "); document.getElementById('result').innerHTML += ('Current value: ' + document.getElementById('progressBar').value + "
    "); document.getElementById('result').innerHTML += ('Mouse click (absolute): ' + event.offsetX + ", " + event.offsetY + "
    "); });
    
    

提交回复
热议问题