HTML5视频控制jQuery问题

时间:2014-11-12 23:39:32

标签: jquery html5 html5-video

我在一个网站上有一个HTML5视频,但是不喜欢刚刚坐在海报图片上的控件的外观,所以我添加了这个jQuery来添加悬停控件,

$('#MSvideo').hover(function toggleControls() {
    if (this.hasAttribute("controls")) {
    this.removeAttribute("controls")
    }
    else {
    this.setAttribute("controls", "controls")
    }
});

理论上这是有效的,它确实添加了悬停控件,但是如果你将鼠标放在视频上,只需坐在那里控件继续,然后关闭,然后打开,然后关闭,大约每秒一次。

在这个小提琴http://jsfiddle.net/konbsda8/

中做同样的事情

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

好的,我想出来了,controls属性需要为空,所以行

  this.setAttribute("controls", "controls")

应该是

  this.setAttribute("controls", "")

这似乎解决了眨眼的效果。