Created
November 11, 2023 13:41
-
-
Save HideyukHira/f96b07c5bef4d2254ecb353006c54847 to your computer and use it in GitHub Desktop.
jQuery html video play seamless
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
//設定部分 再生データの配列 | |
var mp4Array = [ | |
"http://techslides.com/demos/sample-videos/small.mp4", | |
"http://techslides.com/demos/sample-videos/small.mp4" | |
]; | |
//設定 ラップするコンテナdivのid指定 | |
var tgtDiv = '#VideoContainer'; | |
//メイン処理 | |
mp4Array.forEach(makeVideoTag); | |
//メインが呼び出す関数 | |
function makeVideoTag(val, index) { | |
$('<video>') | |
.attr({ | |
id: 'video' + index, | |
src: val, | |
controls: true | |
}) | |
.appendTo($(tgtDiv)) | |
.hide(); | |
if (index !== mp4Array.length - 1) { | |
$(tgtDiv + ' #video' + index).on('ended', function (event) { | |
$(this).hide(); | |
$(this).next().show(); | |
$(this).next()[0].play(); | |
}); | |
} | |
} | |
//HTML処理 生成したHTML<video>1個目を表示化 | |
$(tgtDiv + ' video:eq(0)').show(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment