skB*_*ore 7 javascript video jquery video.js
markers每当它与搜索一起滑动时,我都想移动它。我希望我的标记与jqueryui-slider完全slidable 一样
问题:我希望我的markers(两者)都像jqueryui-range滑块一样可滑动,如下例中的视频所示:
var player = videojs('example_video_1');
function markplayer(){
var inTimeOutTimeList = [6.333,27.667];
for(var i = 0; i < inTimeOutTimeList.length; i++){
player.markers.add([{
time: inTimeOutTimeList[i],
text: inTimeOutTimeList[i]
}]);
var icon = (i == 0) ? '[' : ']';
$(".vjs-marker[data-marker-time='"+inTimeOutTimeList[i]+"']").html(icon);
}
};
player.markers({
breakOverlay:{
display: true,
displayTime: 120,
style:{
'width':'100%',
'height': '30%',
'background-color': 'rgba(10,10,10,0.6)',
'color': 'white',
'font-size': '16px'
}
},
markers: [
{time:10, startTime:10, endTime:60, text: "this", overlayText: "1", class: "special-blue"},
]
});
setTimeout(function(){
markplayer();
},2000);
$( "#slider-range" ).slider({
range: true,
min: 0,
max: 500,
values: [ 75, 300 ],
slide: function( event, ui ) {
$( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
}
});Run Code Online (Sandbox Code Playgroud)
.vjs-fluid {
overflow: hidden;
}
#example_video_1 .vjs-control-bar {
display: block;
}
#example_video_1 .vjs-progress-control {
bottom: 28px;
left: 0;
height: 10px;
width: 100%;
}
.vjs-default-skin.vjs-has-started .vjs-control-bar {
display: block !important;
visibility: visible !important;
opacity: 1 !important;
}
.vjs-marker {
background-color: transparent !important;
height: 20px !important;
font-size: 20px !important;
color: red !important;
font-weight: bold;
}Run Code Online (Sandbox Code Playgroud)
<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>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.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"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>
<video id="example_video_1" width="400" height="210" controls class="video-js vjs-default-skin" data-setup='{ "inactivityTimeout": 0 }'>
<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>
<p><b>I want both of my red markers to be movable/slidable like below slider</b></p>
<div id="slider-range"></div>Run Code Online (Sandbox Code Playgroud)
请帮助我在此先感谢!!!
首先,使用 jQuery UI 的内置方法使您的标记可拖动。
$('body').on('mousedown', '.vjs-marker', function(e) {
$(e.target).draggable({
axis: 'x',
containment: '.vjs-progress-control',
});
}).on('mouseup', function(e) {
$('.vjs-marker').css('top','-8px');
});
Run Code Online (Sandbox Code Playgroud)
由于标记想要碰到进度条的顶部边缘,我给了它一个top: -8pxon mouseup。
然后,将该onMarkerClick方法添加到您的player.markers()调用中以更新时间。
onMarkerClick: function(marker) {
marker.time = player.currentTime();
player.markers.updateTime();
},
Run Code Online (Sandbox Code Playgroud)
我注意到你在 10 秒添加了一个空白标记,所以我用一个空数组替换了它。
markers: []
Run Code Online (Sandbox Code Playgroud)
最后,我添加了一些 Prev 和 Next 按钮,以便您可以看到标记在滑动后起作用。
看了Ma'moun othman 的回答后,我意识到我的解决方案缺少一些东西。与范围滑块示例不同,我的标记可以相互交叉。
所以我使用对象的drag属性draggable来限制标记的范围。
...
drag: function( e, ui ) {
if ( $(e.target).index('.vjs-marker') === 0 ) {
const outPosition = parseInt( $('.vjs-slider .vjs-marker:eq(1)').css('left') );
ui.position.left = Math.min( outPosition, ui.position.left );
}
else {
const inPosition = parseInt( $('.vjs-slider .vjs-marker:eq(0)').css('left') );
ui.position.left = Math.max( inPosition, ui.position.left );
}
}
...
Run Code Online (Sandbox Code Playgroud)
$('body').on('mousedown', '.vjs-marker', function(e) {
$(e.target).draggable({
axis: 'x',
containment: '.vjs-progress-control',
});
}).on('mouseup', function(e) {
$('.vjs-marker').css('top','-8px');
});
Run Code Online (Sandbox Code Playgroud)
onMarkerClick: function(marker) {
marker.time = player.currentTime();
player.markers.updateTime();
},
Run Code Online (Sandbox Code Playgroud)
markers: []
Run Code Online (Sandbox Code Playgroud)
我刚刚向您之前遇到的事件添加了几行slide,并从该事件中使用它.values()来获取开始值和结束值,然后执行marker.reset ()来添加新标记
...
slide: function twsr(event, ui) {
// $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
player.markers.reset([
{
time: ui.values[0],
text: "this",
overlayText: "1",
class: "special-blue"
},
{
time: ui.values[1],
text: "this",
overlayText: "1",
class: "special-blue"
}
]);
for (var i = 0; i < ui.values.length; i++) {
var icon = i == 0 ? "[" : "]";
$(".vjs-marker[data-marker-time='" + ui.values[i] + "']").html(icon);
}
}
...
Run Code Online (Sandbox Code Playgroud)
注意:我对 setTimeOut 感觉不太好,稍后我会检查它,以便有时间修改它。
如果我答对了你的问题,这就是你正在寻找的实现,工作片段:
...
slide: function twsr(event, ui) {
// $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
player.markers.reset([
{
time: ui.values[0],
text: "this",
overlayText: "1",
class: "special-blue"
},
{
time: ui.values[1],
text: "this",
overlayText: "1",
class: "special-blue"
}
]);
for (var i = 0; i < ui.values.length; i++) {
var icon = i == 0 ? "[" : "]";
$(".vjs-marker[data-marker-time='" + ui.values[i] + "']").html(icon);
}
}
...
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function() {
var player = videojs("example_video_1");
function markplayer() {
$("#slider-range").slider({
range: true,
min: 0,
max: player.duration(),
values: [6.333, 27.667],
slide: function(event, ui) {
// $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
player.markers.reset([
{
time: ui.values[0],
text: "this",
overlayText: "1",
class: "special-blue"
},
{
time: ui.values[1],
text: "this",
overlayText: "1",
class: "special-blue"
}
]);
for (var i = 0; i < ui.values.length; i++) {
var icon = i == 0 ? "[" : "]";
$(".vjs-marker[data-marker-time='" + ui.values[i] + "']").html(icon);
}
}
});
var inTimeOutTimeList = [6.333, 27.667];
for (var i = 0; i < inTimeOutTimeList.length; i++) {
player.markers.add([
{
time: inTimeOutTimeList[i],
text: inTimeOutTimeList[i]
}
]);
var icon = i == 0 ? "[" : "]";
$(".vjs-marker[data-marker-time='" + inTimeOutTimeList[i] + "']").html(
icon
);
}
}
player.markers({
breakOverlay: {
display: true,
displayTime: player.duration(),
style: {
width: "100%",
height: "30%",
"background-color": "rgba(10,10,10,0.6)",
color: "white",
"font-size": "16px"
}
},
markers: [
{
time: 10,
startTime: 10,
endTime: 60,
text: "this",
overlayText: "1",
class: "special-blue"
}
]
});
setTimeout(function() {
markplayer();
}, 100);
});Run Code Online (Sandbox Code Playgroud)
.vjs-fluid {
overflow: hidden;
}
#example_video_1 .vjs-control-bar {
display: block;
}
#example_video_1 .vjs-progress-control {
bottom: 28px;
left: 0;
height: 10px;
width: 100%;
}
.vjs-default-skin.vjs-has-started .vjs-control-bar {
display: block !important;
visibility: visible !important;
opacity: 1 !important;
}
.vjs-marker {
background-color: transparent !important;
height: 20px !important;
font-size: 20px !important;
color: red !important;
font-weight: bold;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1080 次 |
| 最近记录: |