Skip to content

Commit b637062

Browse files
authored
Merge pull request #211 from Oneami/master
#13 Catalog products : photo slider
2 parents 233bbdf + 997f221 commit b637062

File tree

3 files changed

+181
-71
lines changed

3 files changed

+181
-71
lines changed

src/resources/js/scripts.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ $(function () {
8989

9090
$('form#oneclick-form').trigger('submit');
9191
});
92+
93+
$(document).on('mouseenter', '.js-productItemImages', function () {
94+
let imageBlocks = $(this).find('.js-productItemImagesContainer').children('div');
95+
let childsCount = imageBlocks.length;
96+
let width = $(this).width();
97+
let curIndex = 0;
98+
$(this).mousemove(function (getCurrentPos) {
99+
let percentPart = (getCurrentPos.offsetX * 100) / width;
100+
let index = Math.abs(Math.floor(percentPart / (100 / childsCount)));
101+
if (index < childsCount && index !== curIndex) {
102+
imageBlocks.css({ 'display': 'none' });
103+
$(imageBlocks[index]).css({ 'display': 'block' });
104+
curIndex = index;
105+
}
106+
});
107+
});
108+
109+
$(document).on('mouseleave', '.js-productItemImages', function () {
110+
$(this).find('.js-productItemImagesContainer').css({ 'display': 'none' });
111+
$(this).find('.js-productItemImagesContainer').first().css({ 'display': 'block' });
112+
});
92113
});
93114

94115
window.sizesValidate = function () {

0 commit comments

Comments
 (0)