1

是的,我知道有很多类似的问题,但我发现它们对我没有帮助。我有这样的情况:(包括 jwplayer.js 和所有关于 fancyBox 的东西)

< a class="jwVideo" href="" rel="group" > Preview < /a >


$(function() {    
    $(".jwVideo").click(function() {
           $.fancybox({
                'padding' : 0,
                'autoscale' : false,
                'transitionIn' : 'none',
                'transitionOut': 'none',
                'title'  : this.title,
                'width'  : 640,
                'height' : 385,
                'href'    : this.href,
                'type'    : 'swf',
                'swf'   : { 'wmode':'transparent', 
                            'allowfullscreen':'true' 
                }
            });
            return false;
        });
    });

我正是需要这个脚本的“模板”,所以我的问题是如何调整 href 属性以播放位于例如https://bla-bla.something1.amazon.com/video_1.mp4上的视频。

谢谢。

编辑:感谢 JFK 和 Ethan 的帮助,我解决了问题,所以如果有人有类似的问题,这里是解决方案(为我工作):

解决方案:

//html
<a class="jwVideo" href="https://bla-bla123.com/video_1.mp4" rel="group"> Preview </a>
//js
$(function() {
    $("a.jwVideo").click(function() {
        var myVideo = this.href; // Dont forget about 'this'

        $.fancybox({
            padding : 0,
            content: '<div id="video_container">Loading the player ... </div>',
            afterShow: function(){
                jwplayer("video_container").setup({ 
                    file: myVideo,
                    width: 640,
                    height: 385 
                });
            }
        });
        return false;
    });
});
4

1 回答 1

0

如果您在 jwplayer 版本 6 中使用 jquery 库和 fancybox,您会这样做

  $(function() { //this is much better then $(document).ready(function(){});

  $(".jwVideo").click(function(event) { //select class attribute jwVideo assigned to a tag
    var myVideo = $(this).attr('href'); // select the video link from a tag in jwVideo class

   //in the fancybox jwplayer setup code assign myVideo to file
    $.fancybox({
            maxWidth    : 800,
    maxHeight   : 600,
    fitToView   : false,
    width       : '70%',
    height      : '70%',
    autoSize    : false,
    closeClick  : false,
    openEffect  : 'none',
    closeEffect : 'none',
        content: '<div id="video_container">Loading the player ... </div>',
        afterShow: function(){
            jwplayer("video_container").setup({ 
                file: ""+ myVideo +"",
    image: "",
    width: '100%',
    aspectratio: '16:9',
    fallback: 'false',
    autostart: 'true',
    primary: 'flash',
    controls: 'true'
            });
        }
    });

    event.preventDefault(); //prevent default click..if this isn't here then browser will download the mp4 file instead of embedding jwplayer in fancybox
});


});
于 2014-01-01T16:43:07.237 回答