请参见http://jsfiddle.net/rabelais/DW5CV/15/
这里有一种艺术作品的幻灯片,其中包含带有图像和视频的 div。当用户单击全屏图像或视频时,它会隐藏并显示下一行,并继续循环。视频设置为自动播放,但是我希望它们在显示时自动播放并在隐藏时暂停?
$(function () {
var win = $(window),
fullscreen = $('.full'),
image = fullscreen.find('img, video'),
imageWidth = image.width(),
imageHeight = image.height(),
imageRatio = imageWidth / imageHeight;
function resizeImage() {
var winWidth = win.width(),
winHeight = win.height(),
winRatio = winWidth / winHeight;
if (winRatio > imageRatio) {
image.css({
width: winWidth,
height: Math.round(winWidth / imageRatio)
});
} else {
image.css({
width: Math.round(winHeight * imageRatio),
height: winHeight
});
}
}
$('.full').click(function () {
$(this).hide();
if($(this).next('.full').length === 1)
$(this).next('.full').show();
else
$('.full').eq(0).show();
});
});