将HTML插入fancybox关闭按钮

Dav*_*VII 3 jquery fancybox fancybox-2

我想使用html而不是图像为fancybox关闭按钮.

这是我认为应该工作的:

$('.fancybox-media').fancybox({
    afterLoad : function() {
        $('div.fancybox-close').html('X');
    }
});
Run Code Online (Sandbox Code Playgroud)

只关注这里的关闭按钮.任何想法为什么这不起作用?

JFK*_*JFK 6

对于fancybox v2.x,您可以使用该选项tpl设置您想要的任何html

$(".fancybox").fancybox({
 tpl: {
  closeBtn: '<div title="Close" id="myCloseID ">[CLOSE]</div>'
 }
});
Run Code Online (Sandbox Code Playgroud)

请注意,在此示例中,我将自己的选择器id="myCloseID "设置为closecontainer(closeBtn),因此我可以将自己的css样式添加到新的html中,如:

#myCloseID {
 position: absolute; /* this is important */
 z-index: 8040; /* this is important */
 top: -18px; /* or whatever needed */
 right: -10px;
 width: 50px; /* or whatever needed */
 height: 36px;
 cursor: pointer;
 color : #ff0034; /* or whatever needed */
 /* etc. */
}
Run Code Online (Sandbox Code Playgroud)

最终,你可能更愿意使用默认tplcloseBtn用自己的HTML

$(".fancybox").fancybox({
 tpl: {
  closeBtn: '<div title="Close" class="fancybox-item fancybox-close">[my closing html]</div>'
 }
});
Run Code Online (Sandbox Code Playgroud)

...只需通过css删除背景图像

.fancybox-close {
 background-image: none; /* prevents the use of the fancybox sprite */
 color : #ff0034; /* or whatever needed, etc. */
 /* etc. */
}
Run Code Online (Sandbox Code Playgroud)