为什么在FancyBox中第二次点击后没有显示标题?

时间:2014-11-15 12:14:10

标签: javascript jquery fancybox fancybox-2

页面上有一些视频链接可通过点击播放视频:

<div class="play" id="27" data-width="850" data-height="470" data-fancybox-href="https://www.youtube.com/embed/zqO7epdsSic"></div>

当我点击链接然后回调beforeLoad: function () {}调用函数getVideo(){},它返回全局变量中的标题。在回调中,此标题由当前窗口FancyBox指定。 因此,有时不会显示此标题。我如何改进此代码并修复?

代码JS:

$(".play").fancybox({
        type: 'iframe',
        maxWidth: "90%",
        padding: 0,
        autoCenter: false,
        scrolling: 'no',
        fitToView: false,

        beforeLoad: function () {
            var id = $(this.element).attr("id");
            var info = '?theme=dark&color=white&autohide=1&rel=0&iv_load_policy=3&modestbranding=1&enablejsapi=1&origin=http://whoismed.com&showinfo=0&autoplay=1';
            this.href = this.href + info;

            getVideo(id, this, function (response, th) {
                th.title = th.title + response.template;
                th.width = $(th.element).data("width");
                th.height = $(th.element).data("height");
            });
        },

        afterLoad: function () {
            //changeURL(_videoInfo.info.VideoCode+'#'+_videoInfo.info.idVideo, _videoInfo.info.VideoName, _videoInfo.info);
        },

        helpers: {
            overlay: {
                locked: false
            },
            title: {
                type: 'inside' // to append the html
            }
        }
    });

功能GetVideo();

function getVideo(id, th, callback) {
    var th = th;
    $.ajax({
        type: "POST",
        dataType: "json",
        data: {id: id},
        url: '/comments/GetHash',
        success: function (result) {

            info = result.info[0];
            hash = result.hash;

            _videoInfo.info = info;
            _videoInfo.template = parseTpl(userInfoVideo, {
                'name': info.DetailToUsersName,
                'id_user': info.idDetailToUsers,
                'time': info.VideoTime,
                'desc': info.VideoDescription,
                'id': info.idVideo,
                'title': info.VideoName,
                'category': info.SpecializationName,
                'category_id': info.idSpec,
                'likes': result.statistic,
                'form': result.formComment,
                'comments': result.comments,
                'user_photo': (info.DetailToUsersPhoto == null) ? '/public/images/notphoto.png' : '/' + info.DetailToUsersPhoto
            });

            callback(_videoInfo, th);
        }
    });
}

0 个答案:

没有答案