How to get value from jQuery UI slider?

2019-01-11 16:31发布

I am working on http://gamercity.info/ymusic/. And I am using UI slider as seek bar. While the video is played I want to invoke a seekTo(seconds) function if user clicked anywhere on the seek bar. How to get new value of seconds after click event?

9条回答
SAY GOODBYE
2楼-- · 2019-01-11 16:50

I checked all the answers mentioned above, but found none useful as the following code:

$('#slider').slider("values")[0]; // for slider with single knob or lower value of range
$('#slider').slider("values")[1]; // for highest value of range

Tested with jQuery v2.1.1 and jQuery-ui v1.12.1

查看更多
We Are One
3楼-- · 2019-01-11 16:50

You can pass the value to any function or set any element with the value:

$(function () {
    $('#slider').slider({
        max: 100,
        slide: function (event, ui) {
            $('#anyDiv').val(ui.value);
        }
    });
});
查看更多
仙女界的扛把子
4楼-- · 2019-01-11 16:53

Late to the party but this question has still unanswered.

Below example will show you how to get value on change in an input field to save in DB:

$( "#slider-videoTransparency" ).slider({            
  value: "1",
  orientation: "horizontal",
  range: "min",
  max: 30,
  animate: true,
  change: function (e, ui) {

    var value = $(this).slider( "value" );
    $('.video_overlay_transparency').val(value);
  }  
});
<div id="slider-videoTransparency" class="slider-danger"></div>

<input type="hidden" name="video_overlay_transparency" class="video_overlay_transparency" value="">

查看更多
登录 后发表回答