new
This commit is contained in:
@ -146,9 +146,31 @@ function TCGallery(parent)
|
||||
}
|
||||
|
||||
//Галерея изображений на странице товара (Двигается в право в лево)
|
||||
function TCGallery2(parent)
|
||||
class TCGallery2
|
||||
{
|
||||
this.addImage = function(small)
|
||||
constructor(parent) {
|
||||
this.parent=parent; //Элемент который будем двигать в право в лево
|
||||
|
||||
this.mas = new Array(); //Массим элементов с рисуночками
|
||||
this.pos=0;
|
||||
this.ower=true;
|
||||
|
||||
this.iWidth=200; //Размер картинки по умолчанию
|
||||
|
||||
// повторить с интервалом 2 секунды
|
||||
setInterval(() => this.resize(), 1000);
|
||||
}
|
||||
|
||||
//Подстраиваюсь под размер родительского компонента
|
||||
resize()
|
||||
{
|
||||
let pDiv = this.parent.parentElement;
|
||||
|
||||
this.parent.style.width = pDiv.offsetWidth+'px';
|
||||
}
|
||||
|
||||
//Добавляю кнопочки для переключения картинок
|
||||
addImage(small)
|
||||
{
|
||||
this.mas.push({div: small, sell: false});
|
||||
|
||||
@ -156,9 +178,9 @@ function TCGallery2(parent)
|
||||
{ return function()
|
||||
{
|
||||
if(!thiz.ower) return;
|
||||
|
||||
pos=-1;
|
||||
for(i=0;i<thiz.mas.length;i++) if(small===thiz.mas[i].div) { pos=i;} //Позиция элемента в массиве
|
||||
|
||||
let pos=-1;
|
||||
for(let i=0;i<thiz.mas.length;i++) if(small===thiz.mas[i].div) { pos=i;} //Позиция элемента в массиве
|
||||
if(pos===-1) return;
|
||||
|
||||
if(thiz.ower && pos!== thiz.pos )
|
||||
@ -171,8 +193,9 @@ function TCGallery2(parent)
|
||||
small.onclick = function(thiz,small)
|
||||
{ return function()
|
||||
{
|
||||
pos=-1;
|
||||
for(i=0;i<thiz.mas.length;i++) if(small===thiz.mas[i].div) { pos=i; } else { thiz.mas[i].div.style.borderColor="#dfdfdf"; thiz.mas[i].sell=false; } //Позиция элемента в массиве
|
||||
|
||||
let pos=-1;
|
||||
for(let i=0;i<thiz.mas.length;i++) if(small===thiz.mas[i].div) { pos=i; } else { thiz.mas[i].div.style.borderColor="#dfdfdf"; thiz.mas[i].sell=false; } //Позиция элемента в массиве
|
||||
if(pos===-1) return;
|
||||
|
||||
if(!thiz.mas[pos].sell) //Если щёлкнули на выделеное 1й раз
|
||||
@ -195,7 +218,7 @@ function TCGallery2(parent)
|
||||
};
|
||||
|
||||
//Плавная прокрутка по горизонтали
|
||||
this.moveTo = function()
|
||||
moveTo()
|
||||
{
|
||||
if(this.parent==null) return;
|
||||
var dx=(this.pos - this.parent.scrollLeft)/20.0; //Шагов для достижения нужного положения
|
||||
@ -205,8 +228,4 @@ function TCGallery2(parent)
|
||||
setTimeout(function(thiz){ return function(){ thiz.moveTo(); } }(this),10);
|
||||
}
|
||||
|
||||
this.mas = new Array(); //Массим элементов с рисуночками
|
||||
this.parent=parent;
|
||||
this.pos=0;
|
||||
this.ower=true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user