开发者

User clicks on Image, video starts playing

I have an image, and I would like to make the image link to an embedded YouTube video, such that if the user clicks on the image, it starts playing in the place where the picture used to be.

<div id="myvideo">
    <a href="http://www.youtube.com/watch?v=Msef24JErmU&playnext_from=TL&videos=dgzKE_Lyv7o">
    <img src="starryeyedsurprise.jpg"></a>
</div>

Something like what the above code does, except not just hyperlink to it. So I know I have to have javaScript replace what's in #myvideo with:

<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Msef24JErmU&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Msef24JErmU&hl=en_US&fs=1&rel=0&color1=0x2b4开发者_如何学C05b&color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>

And then automatically start playing. I guess I don't need it to be a YouTube video per se, I could just host the video on my own site (it's so low volume that I don't have to worry about serving up a video every once in a while).


Just use:

$("#myvideo").html('<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/Msef24JErmU&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Msef24JErmU&hl=en_US&fs=1&rel=0&color1=0x2b405b&color2=0x6b8ab6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>');

...as an onclick handler. For example:

<a href='javascript:void(0);' onclick='DoVideoSwap();'> ... </a>

This will replace the image content with the video.


you can use this

<script type="text/javascript">

    var em = '<video width="640" height="360" controls="controls" autoplay="autoplay"><source src="../video/video.mp4" type="video/mp4"><object  data="" width="640" height="360"><embed width="640" height="360" src="http://something.com/video/video.mp4"> </object> </video>';

    function playVid() {
        document.getElementById('videocontainer').innerHTML = em
    }
</script>
<div>
    <span id="videocontainer" onclick="playVid();">
        <sc:FieldRenderer ID="FieldRenderer2" runat="server" key="Title" FieldName="Image" />
    </span>
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜