if (arg > images.length){
index = 1;
}
if (arg < 1) {
index = images.length;
}
var index = 1;
show (index);
function plus (arg) {
show (index = index + arg);
}
function show (arg) {
var images = document.querySelectorAll(".image");
if (arg > images.length){
index = 1;
}
if (arg < 1) {
index = images.length;
}
for (i = 0; i < images.length; i++) {
images[i].style.display = "none";
}
images[index-1].style.display = "block";
}
var timer=setInterval(function() {plus(1)}, 5000);
var mass = [1,2,3,4,5,6,7,8,9,10];
var out= " ";
for(i = 0; i < mass.length; i++){
out = out + mass[i]
}
document.getElementById('root').innerHTML = out;
out = mass[i]
out = out + mass[i]
var mass = [1,2,3,4,5,6,7,8,9,10];
var out= " ";
for(i = 0; i < mass.length; i++){
out = out + mass[i]
}
document.getElementById('root').innerHTML = out;
out = mass[i]
out = out + mass[i]
var cart = {};
document.addEventListener('DOMContentLoaded', function (e) {
loadGoods();
checkCart();
showMiniCart();
});
function loadGoods() {
$.getJSON('goods.json', function (data) {
var out = '';
for (var key in data){
if (data[key]['sex'] != sex) { continue; } /*отображение товара в зависимости от того какая html страница открыта*/
out+='<div class="single-goods">';
out+='<h3>'+data[key]['name']+'</h3>';
out+='<img src="'+data[key].image+'">';
out+='<p>Цена: '+data[key]['cost']+'</p>';
out+='<button class="add-to-cart" data-art="'+key+'">Купить</button>';
out+='</div>';
}
document.getElementById('goods').innerHTML = out;
document.querySelectorAll('button.add-to-cart').forEach(function(but) {
but.addEventListener("click",addToCart);
})
});
}
function addToCart() { // добавляю товар в мини корзину
var articul = this.getAttribute('data-art');
if (cart[articul]!=undefined) {
cart[articul]++;
}
else {
cart[articul] = 1;
}
localStorage.setItem('cart', JSON.stringify(cart) );
showMiniCart();
}
function checkCart(){
if ( localStorage.getItem('cart') != null) {
cart = JSON.parse (localStorage.getItem('cart'));
}
}
function showMiniCart(){ //отображаю мини-корзину
var out ='';
for (var w in cart){
out += w + ' --- '+cart[w]+'<br>';
}
out+='<br><a href="cart.html">Корзина</a>';
document.getElementById('mini-cart').innerHTML = out;
}