Skip to content

Commit fb7afcd

Browse files
authored
ENGCOM-7456: Prevent product gallery elements from blinking when they load #27871
2 parents 5550eaf + 65ac6ff commit fb7afcd

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

lib/web/mage/gallery/gallery.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ define([
270270
next: $t('Next'),
271271
previous: $t('Previous')
272272
}),
273-
mainImageIndex;
273+
mainImageIndex,
274+
$element = settings.$element,
275+
$fotoramaElement,
276+
$fotoramaStage;
274277

275278
if (settings.breakpoints) {
276279
_.each(_.values(settings.breakpoints), function (breakpoint) {
@@ -285,19 +288,38 @@ define([
285288
settings.breakpoints = breakpoints;
286289
}
287290

288-
_.extend(config, config.options);
289-
config.options = undefined;
290-
291-
config.click = false;
292-
config.breakpoints = null;
291+
_.extend(config, config.options,
292+
{
293+
options: undefined,
294+
click: false,
295+
breakpoints: null
296+
}
297+
);
293298
settings.currentConfig = config;
294-
settings.$element.css('min-height', settings.$element.height());
295-
settings.$element.html(tpl);
296-
settings.$element.removeClass('_block-content-loading');
297-
settings.$elementF = $(settings.$element.children()[0]);
298-
settings.$elementF.fotorama(config);
299-
settings.$element.css('min-height', '');
300-
settings.fotoramaApi = settings.$elementF.data('fotorama');
299+
300+
$element
301+
.css('min-height', settings.$element.height())
302+
.append(tpl);
303+
304+
$fotoramaElement = $element.find('[data-gallery-role="gallery"]');
305+
306+
$fotoramaStage = $fotoramaElement.find('.fotorama__stage');
307+
$fotoramaStage.css('position', 'absolute');
308+
309+
$fotoramaElement.fotorama(config);
310+
$fotoramaElement.find('.fotorama__stage__frame.fotorama__active')
311+
.one('f:load', function () {
312+
// Remove placeholder when main gallery image loads.
313+
$element.find('.gallery-placeholder__image').remove();
314+
$element
315+
.removeClass('_block-content-loading')
316+
.css('min-height', '');
317+
318+
$fotoramaStage.css('position', '');
319+
});
320+
settings.$elementF = $fotoramaElement;
321+
settings.fotoramaApi = $fotoramaElement.data('fotorama');
322+
301323
$.extend(true, config, this.startConfig);
302324

303325
mainImageIndex = getMainImageIndex(config.data);

lib/web/mage/gallery/gallery.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@
395395
position: absolute;
396396
top: 0;
397397
width: @fotorama-arw-size;
398+
399+
._block-content-loading & {
400+
opacity: 0;
401+
}
402+
398403
.fotorama__arr__arr {
399404
&:extend(.fotorama-sprite);
400405
.fotorama-abs-center();

0 commit comments

Comments
 (0)