1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
function videoJs({ playClass = "playOne", pauseClass = "pauseOne" }) { let videoArr = document.querySelectorAll(".video-content"); let coverArr = document.querySelectorAll(".cover"); let playArr = document.querySelectorAll(".play"); let pauseArr = document.querySelectorAll(".pause"); for (let index = 0; index < videoArr.length; index++) { const videoElement = videoArr[index]; let coverTemp = coverArr[index]; let playTemp = playArr[index]; let pauseTemp = pauseArr[index];
playTemp.onclick = function () { coverTemp.style.display = "none"; let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList); let playTempClassList = Array.prototype.slice.call(playTemp.classList) if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) { pauseTemp.classList.remove(pauseClass); } if (playTempClassList.join(",").indexOf(playClass) > 0) { playTemp.classList.remove(playClass); } pauseTemp.classList.add(pauseClass); playTemp.classList.add(playClass); videoElement.play(); } pauseTemp.onclick = function () { coverTemp.style.display = "inline-block"; let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList); let playTempClassList = Array.prototype.slice.call(playTemp.classList) if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) { pauseTemp.classList.remove(pauseClass); } if (playTempClassList.join(",").indexOf(playClass) > 0) { playTemp.classList.remove(playClass); } videoElement.pause(); }
videoElement.onended = function () { coverTemp.style.display = "inline-block"; let pauseTempClassList = Array.prototype.slice.call(pauseTemp.classList); let playTempClassList = Array.prototype.slice.call(playTemp.classList) if (pauseTempClassList.join(",").indexOf(pauseClass) > 0) { pauseTemp.classList.remove(pauseClass); } if (playTempClassList.join(",").indexOf(playClass) > 0) { playTemp.classList.remove(playClass); } } } } videoJs({ playClass: "playOne", pauseClass: "pauseOne" })
|
评论加载中