用户登录
还没有账号?立即注册
用户注册
点击换图
投稿取消
文章分类:
还能输入300字

上传中....

热门文章更多>>
标签更多>>
专题更多>>
最新文章更多>>

如何弹出一个 jquery 窗口来播放 youtube 视频?

<script language="javascript" type="text/javascript">$(函数(){var videoModal = $('#video-modal').overlay({暴露:{颜色:黑色',加载速度:200,不透明度:0.85},closeOnClick: 真,api: 真的});$('.video-link').click(function() {videoModal.load();var videoUrl = $(this).attr('href');var flashvars = {};变量参数 = {允许全屏:真",允许脚本访问:总是"};var 属性 = {};swfobject.embedSWF(videoUrl, 'video-container', '425', '344', '9.0.0', '', flashvars, params, attributes);返回假;});});

I need this video to play automatically. It would be nice, this code can play videos from other sources like yahoo etc.. Is it also possible to use HTML5, instead of jquery?

解决方案

The function or plugin you use to display the popup window will probably be different from what you are using to display the video. In this example I used the Overlay Plugin from jQuery Tools to display the modal then used swfobject to display the YouTube Flash Player. Alternatively, you could use an HTML5 video player with Flash fallback to display the video, but you would still need it to popup your modal first.

<a href="http://www.youtube.com/v/2cxqZiWyW3g&hl=en_US&fs=1&autoplay=1"
    class="video-link">Video 1</a>
<a href="http://www.youtube.com/v/607RMNoJfl4&hl=en_US&fs=1&autoplay=1"
    class="video-link">Video 2</a>

<div class="modal" id="video-modal">
    <div id="video-container" style="width: 425px; height: 344px;"></div>
</div>

<script language="javascript" type="text/javascript">

    $(function() {
        var videoModal = $('#video-modal').overlay({
            expose: {
                color: 'black',
                loadSpeed: 200,
                opacity: 0.85
            },
            closeOnClick: true,
            api: true
        });

        $('.video-link').click(function() {
            videoModal.load();

            var videoUrl = $(this).attr('href');
            var flashvars = {};
            var params = {
                allowFullScreen: "true",
                allowscriptaccess: "always"
            };
            var attributes = {};

            swfobject.embedSWF(videoUrl, 'video-container', '425', '344', '9.0.0', '', flashvars, params, attributes);

            return false;
        });
    });

</script>