- 43
- 0
小插件基本实现了视频播放,只那个小圆点很讨厌闪來闪去的。
我的想法是阻止事件冒泡,亲测了下又不是这方面问题,目前很没有头绪。
HTML布局里小圆点不是作为功能使用的,仅为装饰作用。求大神指教。
html:
<div class="box">
<video src="media/35Q888piCCPd.mp4" controls id="vd"></video>
<div class="circle clearfix">
<a href="javascript:;" class="cirBtn"></a>
<div class="cirProgress"><span class="grayBar"></span><span class="redBar"><em class="dot"></em></span></div>
<div class="cirTime"><span>00:00</span> / <span>00:00</span></div>
</div>
</div>
css:
.box {
margin: 0 auto;
width: 980px;
}
.box video {
display: block;
width: 100%;
height: 640px;
}
.circle {
padding: 10px;
background-color: #333;
}
.cirBtn {
position: relative;
float: left;
width: 40px;
height: 40px;
border: 3px solid #fff;
border-radius: 50%;
}
.cirBtn:after,.cirBtn:before {
position: absolute;
top: 50%;
left: 50%;
content: '';
}
.cirBtn:after {
margin-top: -10px;
margin-left: -5px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 15px solid #fff;
}
.cirPause:after,.cirPause:before {
content: '';
margin-top: -10px;
width: 5px;
height: 20px;
background-color: #fff;
border: 0 none;
}
.cirPause:after {
margin-left: -9px;
}
.cirPause:before {
margin-left: 4px;
}
.cirProgress {
position: relative;
float: left;
margin-left: 15px;
padding: 18px 0;
width: 500px;
height: 10px;
cursor: pointer;
}
.cirProgress .grayBar,.cirProgress .redBar {
position: absolute;
top: 50%;
left: 0;
margin-top: -1.5px;
height: 3px;
}
.cirProgress .grayBar {
right: 0;
background-color: #ccc;
}
.cirProgress .redBar {
background-color: #ea4646;
}
.cirProgress .dot {
position: absolute;
top: 50%;
right: 0;
margin-top: -6px;
margin-right: -6px;
width: 12px;
height: 12px;
background-color: #ea4646;
border-radius: 50%;
cursor: pointer;
}
.cirTime {
float: left;
margin: 10px 0 0 15px;
color: #fff;
font-size: 16px;
line-height: 26px;
}
jq:
var $ele = $('#vd');
var ele = $ele[0];
var currenTime = 0;
var duracTime = 0;
ele.muted = true;
// 当前时长和总时长
ele.onloadedmetadata = function () {
currenTime = ele.currentTime;
duracTime = ele.duration;
$('.cirTime span').eq(0).html(timeFormat(currenTime));
$('.cirTime span').eq(1).html(timeFormat(duracTime));
}
$('.cirBtn').click(function () {
if (ele.paused) {
ele.play();
$(this).addClass('cirPause');
} else {
ele.pause();
$(this).removeClass('cirPause');
}
});
function timeFormat(nums) {
var seconds = Math.floor(nums % 60);
if (seconds < 10) {
seconds = '0' + seconds;
}
var minute = Math.floor(nums / 60);
if (minute < 10) {
minute = '0' + minute;
}
return minute + ':' + seconds;
}
// 进度条跟随
$ele.on('timeupdate',function () {
currenTime = ele.currentTime;
duracTime = ele.duration;
var percent = currenTime / duracTime * 100;
$('.redBar').css('width',percent + '%');
$('.cirTime span').eq(0).html(timeFormat(currenTime));
if (ele.ended) {
$('.cirBtn').removeClass('cirPause');
}
});
// 进度条拖拽
var lock = false;
$('.cirProgress').on('mousedown',function (ev) {
lock = true;
changeCurrentTime(ev.offsetX);
});
$('.circle').on('mouseup',function (ev) {
if (lock == true) {
lock = false;
changeCurrentTime(ev.offsetX);
}
}).on('mousemove',function (ev) {
ev.stopPropagation();
ev.preventDefault();
if (lock == true) {
changeCurrentTime(ev.offsetX);
}
})
// 改变当前时间
function changeCurrentTime(x) {
var percent = x / $('.cirProgress').width() * 100;
if (percent >= 100) {
percent = 100;
}
if (percent <= 0) {
percent = 0;
}
$('.redBar').css('width',percent + '%');
ele.currentTime = percent * duracTime / 100;
$('.cirTime span').eq(0).html(timeFormat(ele.currentTime));
} - 共 0 条
- 全部回答
-
紫夜天狼 普通会员 1楼
在jQuery中,拖动进度条时,如果拖动的小圆点出现闪现现象,可能是由于以下几种原因:
-
约束高度设置过低:在拖动进度条时,如果进度条的高度设置过低,超出小圆点可视区域,就会导致小圆点在拖动过程中闪烁。可以通过设置
position属性的值来调整进度条的高度,如position: relative; left: 50%; top: 50%; transform: translate(-50%, -50%),这将使进度条相对于其容器的位置进行缩放。 -
拖动事件处理不当:在拖动进度条时,如果没有正确地添加拖动事件监听器,或者处理错误的拖动事件,可能会导致小圆点在拖动过程中闪烁。可以使用
mousedown和mousemove事件来监听拖动操作,然后在事件处理函数中处理进度条的移动和缩放。例如:
javascript $(document).ready(function() { $("#myProgress").draggable({ dragStart: function(event, ui) { ui.target.style.backgroundColor = "red"; }, drag: function(event, ui) { if (ui.position.left < 0 || ui.position.left + ui.helperRect.left > $("#myProgress").width()) { ui.helperRect.left = ui.position.left; } if (ui.position.top < 0 || ui.position.top + ui.helperRect.top > $("#myProgress").height()) { ui.helperRect.top = ui.position.top; } $(this).css("left", ui.position.left - 100 + "%"); $(this).css("top", ui.position.top - 100 + "%"); }, dragEnd: function(event, ui) { $(this).css("left", ui.position.left + 100 + "%"); $(this).css("top", ui.position.top + 100 + "%"); } }); });-
jQuery插件问题:在使用jQuery插件时,如
<progress>或<span>等,如果有额外的样式设置,如透明度、颜色、宽度、高度等,可能会导致小圆点在拖动过程中闪烁。在这种情况下,可以尝试删除这些样式,或者在dragStart和dragEnd事件处理函数中删除这些样式。 -
jQuery动画设置问题:如果使用了jQuery动画,如
animate或animate.css等,也可能会导致小圆点在拖动过程中闪烁。在这种情况下,可以检查动画设置是否正确,确保动画仅在拖动进度条时生效。
以上是可能的解决方案,具体原因可能需要根据你的具体需求和代码情况进行排查和修改。如果问题依然存在,可能需要进行更深入的代码分析和测试,或者寻求专业的jQuery开发人员的帮助。
-
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部

