如何使标记动态地标记进度的任何位置

我的标记有问题,我希望标记可以拉伸以标记进度条上的任何位置

如下图GIF

http://img1.mukewang.com/61d823bc00011bae00150009.jpg

问题:我想选择进度条上的任意一点,并且能够拉伸标记,可以是多个标记点。


我不知道如何使用以下代码:


var player = videojs('demo');


player.markers({

   markerStyle: {

      'width':'9px',

      'border-radius': '40%',

      'background-color': 'orange'

   },

   markerTip:{

      display: true,

      text: function(marker) {

         return "I am a marker tip: "+ marker.text;

      }

   },

   breakOverlay:{

      display: true,

      displayTime: 4,

      style:{

         'width':'100%',

         'height': '30%',

         'background-color': 'rgba(10,10,10,0.6)',

         'color': 'white',

         'font-size': '16px'

      },

      text: function(marker) {

         return "This is a break overlay: " + marker.overlayText;

      },

   },

   markers: [

      {time: 9.5, text: "this", overlayText: "1", class: "special-blue"},

      {time: 16,  text: "is", overlayText: "2"},

      {time: 23.6,text: "so", overlayText: "3"},

      {time: 28,  text: "cool", overlayText: "4"}

   ]

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="http://vjs.zencdn.net/4.2/video.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs-markers.js"></script>

<link href="http://vjs.zencdn.net/4.2/video-js.css" rel="stylesheet"/>

<link href="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs.markers.min.css" rel="stylesheet"/>

<video id="demo" width="400" height="210" controls class="video-js vjs-default-skin">

   <source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">

   <source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">

</video>


翻阅古今
浏览 211回答 2
2回答

一只名叫tom的猫

在你想要指针的地方,只需将时间放在time: 20.5并增加 的宽度markerStyle: { 'width': '190px' },这样你就会在视频进度条中得到长线!开始了var player = videojs('demo');player.markers({&nbsp; &nbsp;markerStyle: {&nbsp; &nbsp; &nbsp; 'width':'190px',&nbsp; &nbsp; &nbsp; 'border-radius': '2px',&nbsp; &nbsp; &nbsp; 'background-color': 'orange'&nbsp; &nbsp;},&nbsp; &nbsp;markerTip:{&nbsp; &nbsp; &nbsp; display: true,&nbsp; &nbsp; &nbsp; text: function(marker) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return "I am a marker tip: "+ marker.text;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;},&nbsp; &nbsp;breakOverlay:{&nbsp; &nbsp; &nbsp; display: true,&nbsp; &nbsp; &nbsp; displayTime: 120,&nbsp; &nbsp; &nbsp; style:{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'width':'100%',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'height': '30%',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'background-color': 'rgba(10,10,10,0.6)',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'color': 'white',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'font-size': '16px'&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; text: function(marker) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return "This is a break overlay: " + marker.overlayText;&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp;},&nbsp; &nbsp;markers: [&nbsp; &nbsp; &nbsp; {time: 20.5, text: "this", overlayText: "1", class: "special-blue"},&nbsp; &nbsp;]});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="http://vjs.zencdn.net/4.2/video.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs-markers.js"></script><link href="http://vjs.zencdn.net/4.2/video-js.css" rel="stylesheet"/><link href="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs.markers.min.css" rel="stylesheet"/><video id="demo" width="400" height="210" controls class="video-js vjs-default-skin">&nbsp; &nbsp;<source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">&nbsp; &nbsp;<source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm"></video>你可以在这里学习更多关于docs 的所有内容。如果您有任何问题,请告知我们!快乐编码!

慕侠2389804

一种方法是在 seekbar 上挂钩mousedown和mousemove事件。使用自定义类在 mousedown 上添加标记。然后在 mousemove 上计算移动并使用自定义类将宽度添加到标记元素。看这个例子:var player = videojs('demo');// Set variable so we can add values laterlet lastAddedMarker = null;let moving = false;let seekBar = player.controlBar.progressControl.seekBar;let startPoint = 0;// When seekbar is clicked add marker and set values to startpoint and set moving flag to trueseekBar.on('mousedown', function(event) {&nbsp; var seekBarEl = this.el();&nbsp; startPoint = videojs.dom.getPointerPosition(seekBarEl, event).x;&nbsp; player.markers.add([{&nbsp; &nbsp; time: player.currentTime(),&nbsp; &nbsp; text: "I'm new",&nbsp; &nbsp; overlayText: "I'm new",&nbsp; &nbsp; class: 'custom-marker'&nbsp; }]);&nbsp; lastAddedMarker = jQuery(".custom-marker");&nbsp; moving = true;});// When user moves while on seekbar get the width and set it to 'custom-marker' classseekBar.on("mousemove", function(e) {&nbsp; if (moving) {&nbsp; &nbsp; let seekBarEl = this.el();&nbsp; &nbsp; let movingPoint = videojs.dom.getPointerPosition(seekBarEl, event).x;&nbsp; &nbsp; let containerWidth = jQuery(seekBarEl).width();&nbsp; &nbsp; let markerWidth = containerWidth * (movingPoint - startPoint);&nbsp; &nbsp; lastAddedMarker.width(markerWidth + "px");&nbsp; }});jQuery(document).on("mouseup", function() {&nbsp; moving = false;});player.markers({&nbsp; markerStyle: {&nbsp; &nbsp; 'width': '9px',&nbsp; &nbsp; 'border-radius': '2px',&nbsp; &nbsp; 'background-color': 'orange'&nbsp; },&nbsp; markerTip: {&nbsp; &nbsp; display: true,&nbsp; &nbsp; text: function(marker) {&nbsp; &nbsp; &nbsp; return "I am a marker tip: " + marker.text;&nbsp; &nbsp; }&nbsp; },&nbsp; onMarkerClick: function(marker) {&nbsp; &nbsp; console.log("AS");&nbsp; },&nbsp; breakOverlay: {&nbsp; &nbsp; display: true,&nbsp; &nbsp; displayTime: 4,&nbsp; &nbsp; style: {&nbsp; &nbsp; &nbsp; 'width': '100%',&nbsp; &nbsp; &nbsp; 'height': '30%',&nbsp; &nbsp; &nbsp; 'background-color': 'rgba(10,10,10,0.6)',&nbsp; &nbsp; &nbsp; 'color': 'white',&nbsp; &nbsp; &nbsp; 'font-size': '16px'&nbsp; &nbsp; },&nbsp; &nbsp; text: function(marker) {&nbsp; &nbsp; &nbsp; return "This is a break overlay: " + marker.overlayText;&nbsp; &nbsp; },&nbsp; },&nbsp; markers: []});.vjs-marker {&nbsp; position: absolute;&nbsp; left: 0;&nbsp; bottom: 0;&nbsp; opacity: 1;&nbsp; height: 100%;&nbsp; transition: opacity .2s ease;&nbsp; -webkit-transition: opacity .2s ease;&nbsp; -moz-transition: opacity .2s ease;&nbsp; z-index: 100}.vjs-break-overlay,.vjs-tip {&nbsp; visibility: hidden;&nbsp; position: absolute;&nbsp; z-index: 100000}.vjs-marker:hover {&nbsp; cursor: pointer;&nbsp; -webkit-transform: scale(1.3, 1.3);&nbsp; -moz-transform: scale(1.3, 1.3);&nbsp; -o-transform: scale(1.3, 1.3);&nbsp; -ms-transform: scale(1.3, 1.3);&nbsp; transform: scale(1.3, 1.3)}.vjs-tip {&nbsp; display: block;&nbsp; opacity: .8;&nbsp; padding: 5px;&nbsp; font-size: 10px;&nbsp; bottom: 14px}.vjs-tip .vjs-tip-arrow {&nbsp; background: url(data:image/gif;base64,R0lGODlhCQAJAIABAAAAAAAAACH5BAEAAAEALAAAAAAJAAkAAAIRjAOnwIrcDJxvwkplPtchVQAAOw==) bottom left no-repeat;&nbsp; bottom: 0;&nbsp; left: 50%;&nbsp; margin-left: -4px;&nbsp; position: absolute;&nbsp; width: 9px;&nbsp; height: 5px}.vjs-tip .vjs-tip-inner {&nbsp; border-radius: 3px;&nbsp; -moz-border-radius: 3px;&nbsp; -webkit-border-radius: 3px;&nbsp; padding: 5px 8px 4px;&nbsp; background-color: #000;&nbsp; color: #fff;&nbsp; max-width: 200px;&nbsp; text-align: center}.vjs-break-overlay {&nbsp; top: 0}.vjs-break-overlay .vjs-break-overlay-text {&nbsp; padding: 9px;&nbsp; text-align: center}<link href="https://vjs.zencdn.net/7.5.5/video-js.css" rel="stylesheet"/><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.6.5/video.min.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs.markers.min.css" rel="stylesheet" /><script src="https://cdnjs.cloudflare.com/ajax/libs/videojs-markers/0.7.0/videojs-markers.min.js"></script><video id="demo" width="400" height="210" controls class="video-js vjs-default-skin">&nbsp; <source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">&nbsp; <source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm"></video>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript