如何在JavaScript中创建一个拖动条(seekbar)

3
我正在开发一个基于Chromeless和YouTube JS API的Web应用程序,用于浏览YouTube视频。我可以轻松实现播放、暂停、静音等功能,但不确定如何创建进度条。
1个回答

1

你可以使用/自定义jQuery UI提供的滑块控件来解决你的问题

更新:你在评论中请求的代码示例。相同的示例已上传至http://elangovanr.com/samples/jquery/slider.html


<!DOCTYPE html>
<html>
<head>
  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
    <style type="text/css">
    #slider { margin: 10px; }
  </style>
  <script>
      $(document).ready(function () {
          $("#slider").slider(
          {
              min: 0,
              max: 100,
              step: 1,
              change: showValue

          });
          $("#update").click(function () {
              $("#slider").slider("option", "value", $("#seekTo").val());

          });
          function showValue(event, ui) {
              $("#val").html(ui.value);
          }
      });
  </script>
</head>
<body style="font-size:62.5%;">
  <p>
  The jQuery UI Slider plugin makes selected elements into sliders. There are various options such as multiple handles, and ranges. The handle can be moved with the mouse or the arrow keys.
  </p>
  <p>
  This sample demonstrates the simple usage of the slider seek to function.
  For more information about slider, please procedd to http://docs.jquery.com/UI/Slider
  </p>
<div id="slider"></div>
Seek To : <input id="seekTo" type="text" value="10" />
<input id="update" type="button" value="Update" />
Current Value : <span id="val">0</span>
</body>
</html>

我对jQuery还不熟悉,没听懂你的意思。 有没有示例可以参考? - atinder
试一试<!DOCTYPE html><html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <style type="text/css"> #slider { margin: 10px; } </style> <script> $(document).ready(function() { $("#slider").slider(); }); </script> </head> <body style="font-size:62.5%;"> <div id="slider"></div> </body> </html> - Elangovan
请查看页面http://docs.jquery.com/UI/Slider中的演示和源代码,这可能会对您有所帮助。 - Elangovan
我有一个 seekTo() 函数,如何在滑块上实现它? - atinder
我有一个名为seekTo(seconds)的函数,如何在滑块上实现它? - atinder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接