Magento 2: How to set first image of product slider after cancel or exit fullscreen popup of image slider.

By default its display current selected image after exit popup in detail page. I have to display first image of slider which is default image after page load.

Any help would be appericiated.


You can do this by extending the mage/gallery/gallery js module and then calling your JS in the template rather than the core gallery.js file.

Selecting the first element after closing an image can be done like so:

], function ($, Gallery) {
    'use strict';

    return Gallery.extend({

        initFullscreenSettings: function () {
            var settings = this.settings,
                self = this;


            settings.$gallery.on('fotorama:fullscreenexit', function () {
                settings.focusableStart.attr('tabindex', '-1');
                settings.focusableEnd.attr('tabindex', '-1');
                settings.api.updateOptions(settings.defaultConfig.options, true);
                settings.focusableStart.unbind('focusin', this._focusSwitcher);
                settings.focusableEnd.unbind('focusin', this._focusSwitcher);

                if (!_.isEqual(settings.activeBreakpoint, {}) && settings.breakpoints) {
                    settings.api.updateOptions(settings.activeBreakpoint.options, true);
                settings.isFullscreen = false;
                    swipe: true

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.