How to replace default controls with custom button

2019-01-20 09:37发布

In Fancybox 2.1.5 I want to replace the default controls with my custom buttons (new preloader + close/next/prev buttons on sprite).

I'm not sure how to adjust the css code properly. I tried to modify the CSS as follows, but there's something wrong, the 'next' icon shows up in the top right corner instead of the 'close' button.

You can see my code on this gist.

1条回答
Explosion°爆炸
2楼-- · 2019-01-20 10:28

No need to mess with the original CSS file, use the tpl API option instead like

$(".fancybox").fancybox({
    tpl: {
        closeBtn: '<a title="Close" class="fancybox-item fancybox-close myClose" href="javascript:;"></a>'
    }
});

Notice that I added the class myClose so I can set its own specific CSS properties, background image, etc. like

.myClose {
    height: 50px;
    width: 50px;
    background: #ff0000;
}

See JSFIDDLE just as an example.

Do the same for the prev/next icons. Check the API documentation (search for tpl)

查看更多
登录 后发表回答