fanybox不能正确加载内容

fancybox doesnot load the content properly

本文关键字:加载 不能 fanybox      更新时间:2023-09-26

所以我在正文中添加了一个div,这个div会在点击图像a标签时弹出。为了达到身体的叠加效果,我使用了fancybox。然而,我可以将div附加到body,但这个div不会作为一个花哨的盒子加载。有人能帮帮忙吗?

我的代码在这里:

http://jsfiddle.net/refhat/xap9F/60/

进一步,我在fancybox中丢失了一些东西,我也没有看到fancybox右上角的关闭十字在chrome中,点击fancybox上的任何地方只是关闭fancybox,这不应该是这种情况。

下面是一些可以用来创建叠加的代码:

overlay = function () {
    var o, c;
    this.create = function (html) {
        o = $('<div />');
        c = $('<div />');
        h = $('<div>' + html + '</div>').appendTo(c);
        var o_css = {
            'position': 'absolute',
            'top': '0',
            'left': '0',
            'width': '100%',
            'height': '100%',
            'background': '#000', // Background of the overlay (opacity is set later)
            'z-index': '10000',
            'overflow': 'hidden'
        };
        var c_css = {
            'position': 'absolute',
            'top': '50%',
            'left': '50%',
            'width': '300px', // Width of content box
            'height': '200px', // Height of the content box
            'margin-left': '-150px', // Half of content width (used to center the box)
            'margin-top': '-100px', // Half of content height (used to center the box)
            'background': '#fff', // Background of the content
            'color': '#000', // Text color
            'z-index': '10001'
        };
        var h_css = { 'padding': '10px' }; // If you want paddning
        o.css(o_css);
        c.css(c_css);
        h.css(h_css);
        o.fadeTo(0, 0).appendTo('body').fadeTo(500, 0.5); //0.5 is opacity, change from 0.1-1.0
        c.fadeTo(0, 0).appendTo('body').fadeTo(500, 1.0); //1.0 is opacity, change from 0.1-1.0
    }
    this.remove = function () {
        o.remove();
        c.remove();
    }
}

你可以这样称呼它:

$(document).ready(function () {
    o = new overlay();
    o.create('HTML you want to fill the container with, example and image or/and text or maybe a link you later bind o.remove() to'); //This creates the overlay
    o.remove(); // .. and this removes the overlay
});