我希望使用HTML代替图片作为fancybox关闭按钮。
以下是我认为应该有效的方法:
$('.fancybox-media').fancybox({
afterLoad : function() {
$('div.fancybox-close').html('X');
}
});
这里只关注关闭按钮。有什么想法为什么它不能工作?
我希望使用HTML代替图片作为fancybox关闭按钮。
以下是我认为应该有效的方法:
$('.fancybox-media').fancybox({
afterLoad : function() {
$('div.fancybox-close').html('X');
}
});
这里只关注关闭按钮。有什么想法为什么它不能工作?
tpl
来设置所需的任何HTML,例如:$(".fancybox").fancybox({
tpl: {
closeBtn: '<div title="Close" id="myCloseID ">[CLOSE]</div>'
}
});
id="myCloseID "
设置为close
容器(closeBtn
),以便可以向新的html添加自己的css样式。#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. */
}
tpl
来自定义closeBtn
的HTML。$(".fancybox").fancybox({
tpl: {
closeBtn: '<div title="Close" class="fancybox-item fancybox-close">[my closing html]</div>'
}
});
你只需通过CSS移除背景图片,方法如下:
.fancybox-close {
background-image: none; /* prevents the use of the fancybox sprite */
color : #ff0034; /* or whatever needed, etc. */
/* etc. */
}
这应该可以工作,但您还需要将 background
设置为 none
。
试试这个:
$('div.fancybox-close').html('X').css({background:'none',color:'white'});
afterLoad
中使用 alert
会起作用吗?您可以尝试使用 afterShow
回调函数代替 afterLoad
。 - Moin Zaman$('.fancybox-close').html('X').css({background:'none',color:'white'});