【发布时间】:2012-03-26 14:32:29
【问题描述】:
我正在尝试使用 jQuery 绑定 play/pause 和 ended 事件,但是有一个问题:
当我右键单击视频并选择播放或暂停时,图标会正确更改。当我点击播放按钮时,它会变为暂停,但如果我点击暂停按钮继续播放视频,它不会再次变为播放。
谁能告诉我哪里出错了?
这是我的代码:
var PlayVideo = function () {
if ($('#video').attr('paused') == false) {
$('#video').get(0).pause();
} else {
$('#video').get(0).play();
}
};
$('#playbtn').click(PlayVideo);
$('#video').click(PlayVideo);
$('#video').bind('play', function () {
$('.playbtn').addClass('pausebtn');
});
$('#video').bind('pause', function () {
$('.playbtn').removeClass('pausebtn');
});
$('#video').bind('ended', function () {
$('.playbtn').removeClass('pausebtn');
});
CSS:
.playbtn {
display: block;
width: 32px;
height: 32px;
margin-left: 10px;
background: url('../images/play.png') no-repeat;
opacity: 0.7;
-moz-transition: all 0.2s ease-in-out; /* Firefox */
-webkit-transition: all 0.2s ease-in-out; /* Safari and Chrome */
-o-transition: all 0.2s ease-in-out; /* Opera */
transition: all 0.2s ease-in-out;
}
.pausebtn {
display: block;
width: 32px;
height: 32px;
margin-left: 10px;
background: url('../images/pause.png') no-repeat;
opacity: 0.7;
-moz-transition: all 0.2s ease-in-out; /* Firefox */
-webkit-transition: all 0.2s ease-in-out; /* Safari and Chrome */
-o-transition: all 0.2s ease-in-out; /* Opera */
transition: all 0.2s ease-in-out;
}
【问题讨论】:
标签: jquery html events video bind