1. <legend id='olbnx'><style id='olbnx'><dir id='olbnx'><q id='olbnx'></q></dir></style></legend>

  2. <i id='olbnx'><tr id='olbnx'><dt id='olbnx'><q id='olbnx'><span id='olbnx'><b id='olbnx'><form id='olbnx'><ins id='olbnx'></ins><ul id='olbnx'></ul><sub id='olbnx'></sub></form><legend id='olbnx'></legend><bdo id='olbnx'><pre id='olbnx'><center id='olbnx'></center></pre></bdo></b><th id='olbnx'></th></span></q></dt></tr></i><div id='olbnx'><tfoot id='olbnx'></tfoot><dl id='olbnx'><fieldset id='olbnx'></fieldset></dl></div>
    <tfoot id='olbnx'></tfoot>

    <small id='olbnx'></small><noframes id='olbnx'>

      • <bdo id='olbnx'></bdo><ul id='olbnx'></ul>
    1. 如何让滑块的值实时更新?

      How do I get the value of a slider to update in real-time?(如何让滑块的值实时更新?)
    2. <i id='nm3Fq'><tr id='nm3Fq'><dt id='nm3Fq'><q id='nm3Fq'><span id='nm3Fq'><b id='nm3Fq'><form id='nm3Fq'><ins id='nm3Fq'></ins><ul id='nm3Fq'></ul><sub id='nm3Fq'></sub></form><legend id='nm3Fq'></legend><bdo id='nm3Fq'><pre id='nm3Fq'><center id='nm3Fq'></center></pre></bdo></b><th id='nm3Fq'></th></span></q></dt></tr></i><div id='nm3Fq'><tfoot id='nm3Fq'></tfoot><dl id='nm3Fq'><fieldset id='nm3Fq'></fieldset></dl></div>

    3. <legend id='nm3Fq'><style id='nm3Fq'><dir id='nm3Fq'><q id='nm3Fq'></q></dir></style></legend>

          <bdo id='nm3Fq'></bdo><ul id='nm3Fq'></ul>

        • <small id='nm3Fq'></small><noframes id='nm3Fq'>

            <tbody id='nm3Fq'></tbody>
          <tfoot id='nm3Fq'></tfoot>
              • 本文介绍了如何让滑块的值实时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个带有自定义控制栏的 HTML 视频标签,我希望搜索栏和音量栏在用户浏览范围时实时更新它们的值.目前,音量会在用户调整滑块后更新,而不是在用户点击和拖动时更新.

                I have an HTML video tag with a customized control bar and in it I want both the seek bar and volume bar to update their values in real-time as the user scrubs through the range. Currently the volume updates after the user adjusts the slider and not while the user is clicking-and-dragging.

                在 HTML 中,我将它们设置为:

                In HTML I have them set up as such:

                <div id="video-controls">
                // ...
                <input type="range" id="seek-bar" value="0">
                <input type="range" id="volume-bar" min="0" max="1" step="0.01" value="1">
                // ...
                </div>
                

                在我的 JavaScript 中,我将它们连接起来:

                And in my JavaScript I have them hooked up like so:

                // Change current viewing time when scrubbing through the progress bar
                seekBar.addEventListener('change', function() {
                    // Calculate the new time
                    var time = video.duration * (seekBar.value / 100);
                
                    // Update the video time
                    video.currentTime = time;
                });
                
                // Update the seek bar as the video plays
                video.addEventListener('timeupdate', function() {
                    // Calculate the slider value
                    var value = (100 / video.duration) * video.currentTime;
                
                    // Update the slider value
                    seekBar.value = value;
                });
                
                // Pause the video when the seek handle is being dragged
                seekBar.addEventListener('mousedown', function() {
                    video.pause();
                });
                
                // Play the video when the seek handle is dropped
                seekBar.addEventListener('mouseup', function() {
                    video.play();
                });
                
                // Adjust video volume when scrubbing through the volume bar
                volumeBar.addEventListener('change', function() {
                    // Update the video volume
                    video.volume = volumeBar.value;
                });
                

                我想从头开始做这件事,而不是使用像 jQuery 这样的 JavaScript 库,即使我知道该库已经这样做了.我见过的大多数解决方案都涉及 jQuery,但我不想使用它.这是为了:减少对 jQuery 的依赖,允许更多的控制权,主要是作为一种学习体验.

                I want to do this from scratch and not use JavaScript libraries like jQuery even though I know this has already been done for that library. Most of the solutions I've seen involve jQuery but I don't want to use it. This is for: reducing the dependency on jQuery, allowing for more control on my end, and primarily as a learning experience.

                推荐答案

                1. 使用鼠标移动是一种愚蠢的解决方法.有一个名为输入"的事件.
                2. 应在用户将自己提交到特定值(mouserelease、keyup 或 blur)后立即分派更改事件,但请注意 Chrome 和 IE10 对这种不同的输入/更改事件行为的错误实现.(请参阅:https://code.google.com/p/chromium/issues/detail?id=155747)
                3. 如果您想学习 JS,请学习如何构建 JS 并在组件中思考.这比使用原生 JS 与 JQuery 重要得多.例如,您正在使用 id.这意味着您在一页上只能有一个媒体播放器.您省略了 addEventListener 的第三个参数.等等……

                所以解释如何完成工作.取决于您是在标准兼容浏览器(目前只有 FF)还是在 x-browser 环境中进行测试.

                So the explanation how to get things done. Depends wether you are testing in a standards compilant browser (currently only FF) or in x-browser enviroment.

                要在用户与之交互时获取输入的当前值,只需使用输入事件:

                To get the current value of an input while the user is interacting with it, simply use the input event:

                range.addEventListener('input', onInput, false);
                

                这是 FF 的工作演示:http://jsfiddle.net/trixta/MfLrW/

                Here is a working demo for FF: http://jsfiddle.net/trixta/MfLrW/

                如果您想在 Chrome 和 IE 中完成这项工作,您必须使用输入/更改并将它们视为只有输入事件.然后您需要自己计算更改"事件,这并不简单.但这是一个适合您的示例:

                In case you want to get this work in Chrome and IE, you have to use the input/change and treat them like it would be only the input event. Then you need to compute the "change" event yourself, which isn't really simple. But here is a working example for you:

                http://jsfiddle.net/trixta/AJLSV/

                这篇关于如何让滑块的值实时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                1. <legend id='h5uCd'><style id='h5uCd'><dir id='h5uCd'><q id='h5uCd'></q></dir></style></legend>
                    • <tfoot id='h5uCd'></tfoot>
                      <i id='h5uCd'><tr id='h5uCd'><dt id='h5uCd'><q id='h5uCd'><span id='h5uCd'><b id='h5uCd'><form id='h5uCd'><ins id='h5uCd'></ins><ul id='h5uCd'></ul><sub id='h5uCd'></sub></form><legend id='h5uCd'></legend><bdo id='h5uCd'><pre id='h5uCd'><center id='h5uCd'></center></pre></bdo></b><th id='h5uCd'></th></span></q></dt></tr></i><div id='h5uCd'><tfoot id='h5uCd'></tfoot><dl id='h5uCd'><fieldset id='h5uCd'></fieldset></dl></div>

                          <tbody id='h5uCd'></tbody>

                        <small id='h5uCd'></small><noframes id='h5uCd'>

                          <bdo id='h5uCd'></bdo><ul id='h5uCd'></ul>