// 封装jQuery两个类名的切换(注意:this的指代)
(function($) {
$.fn.toggle = function(a, b) {
if (arguments.length == 1) {
$(this).toggleClass(arguments[0]);
} else {
return $(this).hasClass(a) ? $(this).removeClass(a).addClass(b) : $(this).removeClass(b).addClass(a);
}
}
})(jQuery)
等待封装的插件
function youPlay() {
var winH = $(window).height();
$("video").each(function() {
var posTop = $(this).offset().top;
var scrollH = $(window).scrollTop(); //浏览器滚动高度
var targetH = $(this).height();
var needShow = (posTop - winH + winH / 2) <= scrollH && scrollH <= (posTop - winH + winH / 2 + targetH);
if (needShow) {
$('video').each(function() {
$(this)[0].pause();
})
$(this)[0].play();
}
})
}