मैं "प्लेयर" div में एक छवि प्रदर्शित करने की कोशिश कर रहा हूं, और उसके बाद विज़िटर बटन क्लिक करता है, इसे एक वीडियो के साथ प्रतिस्थापित करें (div को iFrame से प्रतिस्थापित करें)। यहां मेरा कोड है:यूट्यूब वीडियो शुरू होने से पहले एक कस्टम तस्वीर दिखाएं
<!DOCTYPE html>
<head>
<style type="text/css">
html {
text-align: center;
}
#player {
display: inline-block;
width: 640px;
height: 360px;
background: url(http://placehold.it/640x360) no-repeat;
}
</style>
</head>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<p><button onclick="playMe()">Play</button></p>
<script>
function playMe() {
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '360',
width: '640',
videoId: 'JW5meKfy3fY',
playerVars: { 'autoplay': 0, 'controls': 0, 'rel': 0, 'showinfo': 0 },
events: {
'onReady': onPlayerReady
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
}
</script>
</body>
</html>
लेकिन यह काम नहीं करता है।
यह काम करता है जब "playMe" फ़ंक्शन हटा दिया जाता है, लेकिन मुझे बटन/div/link क्लिक करने के बाद वीडियो प्रारंभ करने की आवश्यकता होगी। मैंने तस्वीर और वीडियो को div
एस में अलग करने की कोशिश की है, वीडियो के शीर्ष पर चित्र और क्लिक के बाद शीर्ष div को छुपाएं और वीडियो शुरू करें, लेकिन यह काम नहीं करता है।
यह ठीक वैसे ही काम करता है जैसा मैं चाहता था, आपको बहुत धन्यवाद। – Noga