Delete types
This commit is contained in:
@ -1,8 +1,21 @@
|
||||
|
||||
//Галерея изображений на первой странице сайта
|
||||
function TCGallery(parent)
|
||||
class TCGallery
|
||||
{
|
||||
this.work = function()
|
||||
constructor(parent)
|
||||
{
|
||||
this.test=0;
|
||||
|
||||
//Конструктор
|
||||
this.timeout_id =0;
|
||||
this.parent=parent;
|
||||
this.mas = this.getChildsMas(); //Массив элементов которые будут "Галереится"
|
||||
this.mas.sort(function(a,b){return b.style.zIndex-a.style.zIndex;});
|
||||
this.firstmas = [].concat(this.mas); //Первоначальный порядок элементов
|
||||
this.btns = new Array();
|
||||
}
|
||||
|
||||
work()
|
||||
{
|
||||
if(this.mas[0].style.opacity > 0.05)
|
||||
{
|
||||
@ -15,8 +28,8 @@ function TCGallery(parent)
|
||||
//Перестовляем Z индексы первый на последнее место (больший наверху)
|
||||
if(this.mas.length>0)
|
||||
{
|
||||
var z=this.mas[this.mas.length-1].style.zIndex;
|
||||
for(var i=this.mas.length-1;i>0;i--)
|
||||
let z=this.mas[this.mas.length-1].style.zIndex;
|
||||
for(let i=this.mas.length-1;i>0;i--)
|
||||
{
|
||||
this.mas[i].style.zIndex=this.mas[i-1].style.zIndex
|
||||
}
|
||||
@ -24,7 +37,7 @@ function TCGallery(parent)
|
||||
}
|
||||
|
||||
//Поменяли местами востанавливаем прозрачность
|
||||
for(var i=0;i<this.mas.length;i++)
|
||||
for(let i=0;i<this.mas.length;i++)
|
||||
{ this.mas[i].style.opacity = 1;
|
||||
}
|
||||
this.mas.sort(function(a,b){return b.style.zIndex-a.style.zIndex;}); //Сортируем с макс Z индексом наверху в 0ле
|
||||
@ -32,12 +45,12 @@ function TCGallery(parent)
|
||||
this.selected();
|
||||
this.test++;
|
||||
}
|
||||
};
|
||||
}
|
||||
//Стартуем галерею
|
||||
this.Start = function()
|
||||
Init()
|
||||
{
|
||||
var maxz=0;
|
||||
for(var i=0;i<this.mas.length;i++)
|
||||
let maxz=0;
|
||||
for(let i=0;i<this.mas.length;i++)
|
||||
{ this.mas[i].style.opacity = 1;
|
||||
if(maxz<this.mas[i].style.zIndex) maxz=this.mas[i].style.zIndex;
|
||||
}
|
||||
@ -46,11 +59,11 @@ function TCGallery(parent)
|
||||
maxz++;
|
||||
|
||||
//Кнопочки для переключения картинок
|
||||
var cdv=document.createElement('div');
|
||||
let cdv=document.createElement('div');
|
||||
cdv.style.cssText='opacity: 0.7; display: block; position: absolute; bottom: 5px; right: 5px; z-index: '+maxz+'; border: solid 0px red;';
|
||||
for(var i=0;i<this.mas.length;i++)
|
||||
for(let i=0;i<this.mas.length;i++)
|
||||
{
|
||||
var btn=document.createElement('div');
|
||||
let btn=document.createElement('div');
|
||||
btn.style.cssText='cursor: pointer; background-color: #eeeeee; text-align: center; display: inline-block; margin: 2px; border: solid 1px black; width: 17px;';
|
||||
btn.appendChild(document.createTextNode(i+1));
|
||||
btn.onclick = function(thiz,i){return function(){ thiz.moveTo(i); }; }(this,i);
|
||||
@ -59,18 +72,18 @@ function TCGallery(parent)
|
||||
}
|
||||
this.parent.appendChild(cdv);
|
||||
if(this.btns.length>0) this.btns[0].style.backgroundColor='#f3af5a';
|
||||
};
|
||||
}
|
||||
//Переместить на заданный слой (позиция с 0)
|
||||
this.moveTo = function(pos)
|
||||
moveTo(pos)
|
||||
{
|
||||
if(pos<0 || pos>this.firstmas.length - 1) return;
|
||||
var elm=this.firstmas[pos];
|
||||
for(var j=0;j<this.mas.length;j++)
|
||||
let elm=this.firstmas[pos];
|
||||
for(let j=0;j<this.mas.length;j++)
|
||||
{
|
||||
if(this.mas[0]==elm) break;
|
||||
|
||||
var z=this.mas[this.mas.length-1].style.zIndex;
|
||||
for(var i=this.mas.length-1;i>0;i--)
|
||||
let z=this.mas[this.mas.length-1].style.zIndex;
|
||||
for(let i=this.mas.length-1;i>0;i--)
|
||||
{
|
||||
this.mas[i].style.zIndex=this.mas[i-1].style.zIndex
|
||||
}
|
||||
@ -78,67 +91,57 @@ function TCGallery(parent)
|
||||
this.mas.sort(function(a,b){return b.style.zIndex-a.style.zIndex;});
|
||||
}
|
||||
//Поменяли местами востанавливаем прозрачность
|
||||
for(var i=0;i<this.mas.length;i++)
|
||||
for(let i=0;i<this.mas.length;i++)
|
||||
{ this.mas[i].style.opacity = 1.0;
|
||||
}
|
||||
|
||||
clearTimeout(this.timeout_id)
|
||||
this.timeout_id=setTimeout(()=>this.work(),10000);
|
||||
this.selected();
|
||||
};
|
||||
}
|
||||
//Поменялся элемент
|
||||
this.selected = function()
|
||||
selected()
|
||||
{
|
||||
var pos=0;
|
||||
for(var i=0;i<this.firstmas.length;i++)
|
||||
let pos=0;
|
||||
for(let i=0;i<this.firstmas.length;i++)
|
||||
{ if(this.mas[0]==this.firstmas[i])
|
||||
{ pos=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//Обнуляем стили
|
||||
for(var i=0;i<this.btns.length;i++)
|
||||
for(let i=0;i<this.btns.length;i++)
|
||||
this.btns[i].style.backgroundColor='#eeeeee';
|
||||
//Выставляем стиль для выбранного элемента
|
||||
this.btns[pos].style.backgroundColor='#f3af5a';
|
||||
};
|
||||
}
|
||||
|
||||
//Private
|
||||
//Получить детей в виде массива
|
||||
this.getChildsMas = function()
|
||||
getChildsMas()
|
||||
{
|
||||
var mas = new Array();
|
||||
let mas = new Array();
|
||||
if(this.parent!==null)
|
||||
{
|
||||
var child = this.parent.firstChild;
|
||||
while(child)
|
||||
{ if(typeof child.style !== "undefined") //Только те где есть стиль
|
||||
{ mas.push(child);
|
||||
}
|
||||
child = child.nextSibling;
|
||||
let child = this.parent.firstChild;
|
||||
while(child){
|
||||
if(typeof child.style !== "undefined"){ //Только те где есть стиль
|
||||
mas.push(child);
|
||||
}
|
||||
child = child.nextSibling;
|
||||
}
|
||||
}
|
||||
return mas;
|
||||
};
|
||||
}
|
||||
//Private
|
||||
//Получить позицию по объекту (-1 если ненайден)
|
||||
this.getPos = function(obj)
|
||||
getPos(obj)
|
||||
{
|
||||
for(var i=0;i<this.firstmas.length;i++)
|
||||
for(let i=0;i<this.firstmas.length;i++)
|
||||
{ if(this.firstmas[i]==obj) return i;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
this.test=0;
|
||||
|
||||
//Конструктор
|
||||
this.timeout_id =0;
|
||||
this.parent=parent;
|
||||
this.mas = this.getChildsMas(); //Массив элементов которые будут "Галереится"
|
||||
this.mas.sort(function(a,b){return b.style.zIndex-a.style.zIndex;});
|
||||
this.firstmas = [].concat(this.mas); //Первоначальный порядок элементов
|
||||
this.btns = new Array();
|
||||
}
|
||||
}
|
||||
|
||||
//Галерея изображений на странице товара (Двигается в право в лево)
|
||||
|
||||
Reference in New Issue
Block a user