简体   繁体   中英

Add arrows to fancybox in responsive with data-attributed initialized fancybox

I make use of Fancybox 3 which is very cool, only one thing that bothers my client is that there is no visual indication in the responsive version of the box that you can swipe to go to the next pictures.

Now I see on the fancybox doc page that you can afterload and add content that way:

afterLoad : function( instance, current ) {
    if ( instance.group.length > 1 && current.$content ) {
      current.$content.append('<div class="swipeto">Swipe to change pictures</div>');
    }

But I don't make use of the fancybox intialized via javascript, but directly via html attributes. How can I make sure to add something to the fancybox?

You can, for example, edit default settings:

$.fancybox.defaults.afterLoad = function( instance, current ) {
    if ( instance.group.length > 1 && current.$content ) {
      current.$content.append('<div class="swipeto">Swipe to change pictures</div>');
    };
};

I solved it this way, I made some changes to the CSS file of fancybox, to show the controls when on responsive:

@media (max-width: 800px){

.fancybox-button--left, .fancybox-button--right, .fancybox-buttons button:not(.fancybox-button--close) {
    display: inline-block!important;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM