const createXML = obj => Object
.entries(obj)
.map(([ k, v ]) => `<ns1:${k}>${v instanceof Object ? createXML(v) : v}</ns1:${k}>`)
.join('');
const createXML = (obj, tabSize = 2, depth = 0) => {
const indent = ' '.repeat(tabSize * depth);
return Object.entries(obj).map(([ k, v ]) =>
indent +
`<ns1:${k}>${
v instanceof Object
? `\n${createXML(v, tabSize, depth + 1)}\n${indent}`
: v
}</ns1:${k}>`
).join('\n');
};
modal.style.display = "none"
делайте modal.remove()
, и всё будет окей. <div id="address-list"></div>
const addressList = document.querySelector('#address-list');
addressList.innerHTML = markersData.map((n, i) => `
<div class="address-list-item">
<span data-index="${i}">${n.name}</span>
</div>
`).join('');
addressList.addEventListener('click', e => {
const marker = markersData[e.target.dataset.index];
if (marker) {
map.setCenter(new google.maps.LatLng(marker.lat, marker.lng));
}
});
<div><label><input type="checkbox" id="xxx">hello, world!!</label></div>
<div><label><input type="checkbox" id="yyy">fuck the world</label></div>
<div><label><input type="checkbox" id="zzz">fuck everything</label></div>
<div>sum: <input id="sum" readonly></div>
<div>ids: <input id="ids" readonly></div>
document.addEventListener('change', () => {
const cb = document.querySelectorAll('input[type="checkbox"]:checked');
document.querySelector('#sum').value = cb.length * 900;
document.querySelector('#ids').value = Array.from(cb, n => n.id).join(', ');
});
Может написать регулярку, которая будет убирать только первый и последнии слеши?
.slice(1, -1)
.regexp
используется только для задания значений атрибута pattern
, то пусть его свойства будут сразу строками, а не регулярными выражениями. И ещё, зачем делать его обычным полем класса? - так будет создаваться отдельный объект для каждого экземпляра. Пусть будет статическим или вообще не принадлежит классу. function calcRowAndColumn(coordinates) { let currPosition; if (coordinates > 0 && coordinates < 4) { currPosition = 0; } if (coordinates > 4 && coordinates < 8) { currPosition = 1; } if (coordinates > 8 && coordinates < 12) { currPosition = 2; } if (coordinates > 12 && coordinates < 16) { currPosition = 3; } if (coordinates > 16 && coordinates < 20) { currPosition = 4; } if (coordinates > 20 && coordinates < 24) { currPosition = 5; } if (coordinates > 24 && coordinates < 28) { currPosition = 6; } if (coordinates > 28 && coordinates < 32) { currPosition = 7; } if (coordinates > 32 && coordinates < 36) { currPosition = 8; } if (coordinates > 36 && coordinates < 40) { currPosition = 9; } if (coordinates > 40 && coordinates < 44) { currPosition = 10; } if (coordinates > 44 && coordinates < 48) { currPosition = 11; } if (coordinates > 48 && coordinates < 52) { currPosition = 12; } if (coordinates > 52 && coordinates < 56) { currPosition = 13; } if (coordinates > 56 && coordinates < 60) { currPosition = 14; } if (coordinates > 60 && coordinates < 64) { currPosition = 15; } if (coordinates > 64 && coordinates < 68) { currPosition = 16; } if (coordinates > 68 && coordinates < 72) { currPosition = 17; } if (coordinates > 72 && coordinates < 76) { currPosition = 18; } if (coordinates > 76 && coordinates < 80) { currPosition = 19; } if (coordinates > 80 && coordinates < 84) { currPosition = 20; } if (coordinates > 84 && coordinates < 88) { currPosition = 21; } if (coordinates > 88 && coordinates < 92) { currPosition = 22; } if (coordinates > 92 && coordinates < 96) { currPosition = 23; } if (coordinates > 96 && coordinates < 100) { currPosition = 24; } if (coordinates > 100 && coordinates < 104) { currPosition = 25; } if (coordinates > 104 && coordinates < 108) { currPosition = 26; } if (coordinates > 108 && coordinates < 112) { currPosition = 27; } if (coordinates > 112 && coordinates < 116) { currPosition = 28; } if (coordinates > 116 && coordinates < 120) { currPosition = 29; } if (coordinates > 120 && coordinates < 124) { currPosition = 30; } if (coordinates > 124 && coordinates < 128) { currPosition = 31; } return currPosition; }
const calcRowAndColumn = coord => Math.floor(coord / 4);
if (coordinates > 112 && coordinates < 116) { currPosition = 28; } if (coordinates > 116 && coordinates < 120) { currPosition = 29; }
.div1:hover + .div2,
.div2:hover {
display: block;
}
.show {
display: block;
}
let timeout = null;
function onEnter() {
clearTimeout(timeout);
div2.classList.add('show');
}
function onLeave() {
timeout = setTimeout(() => div2.classList.remove('show'), 300);
}
div1.addEventListener('mouseenter', onEnter);
div2.addEventListener('mouseenter', onEnter);
div1.addEventListener('mouseleave', onLeave);
div2.addEventListener('mouseleave', onLeave);
fibbonachi(n[0],left+n[1])
fibbonachi(n[1], left + n[1])
options: {
scales: {
yAxes: [ {
ticks: {
reverse: true,
min: 0,
max: // здесь ваше "заданное число"
},
} ],
},
},
function initSlider(el) {
if (!(el instanceof HTMLElement)) {
el = document.querySelector(el);
}
const slider = new Swiper(el.querySelector('.product-slider'), {
navigation: {
nextEl: el.querySelector('.swiper-button-next'),
prevEl: el.querySelector('.swiper-button-prev'),
},
spaceBetween: 10,
});
const thumbs = new Swiper(el.querySelector('.product-thumbs'), {
spaceBetween: 5,
centeredSlides: true,
slidesPerView: 4,
touchRatio: 0.2,
slideToClickedSlide: true,
direction: 'vertical',
});
slider.controller.control = thumbs;
thumbs.controller.control = slider;
return { slider, thumbs };
}
const
first = initSlider('.container-first'),
second = initSlider('.container-second');
document.querySelector('.set-slide').addEventListener('click', () => {
second.slider.slideTo(first.slider.realIndex);
});
const getQueryArray = (obj, path = [], result = []) =>
Object.entries(obj).reduce((acc, [ k, v ]) => {
path.push(k);
if (v instanceof Object) {
getQueryArray(v, path, acc);
} else {
acc.push(`${path.map((n, i) => i ? `[${n}]` : n).join('')}=${v}`);
}
path.pop();
return acc;
}, result);
const getQueryString = obj => getQueryArray(obj).join('&');
const getQueryString = (obj, path = '') =>
Object.entries(obj).reduce((acc, [ k, v ]) => (
path && (k = `${path}[${k}]`),
acc + (acc && '&') + (v instanceof Object
? getQueryString(v, k)
: `${k}=${v}`
)
), '');
position: absolute;
для .tabsPanelHidden
.get
, можно ничем его не заменять. При обработке клика вместо первого попавшегося audio
надо хватать тот, что соответствует нажатой кнопке (это же касается элементов .play
и .pause
, с той лишь разницей, что тут вы хватаете всё, что есть), т.е., который находится в том же .container
. От кликнутого элемента поднимаемся к .container
и ищем внутри него нужные элементы:$(document).on('click', '.play, .pause', function() {
const $this = $(this);
const $container = $this.closest('.container');
const isPlay = $this.hasClass('play');
$container.find('.play').toggleClass('active', isPlay);
$container.find('.pause').toggleClass('active', !isPlay);
$container.find('audio').get(0)[isPlay ? 'play' : 'pause']();
});
.slider::before,
.slider::after {
position: absolute;
top: 50%;
transform: translateY(-50%);
z-index: 666;
}
.slider::before {
left: 0;
content: attr(data-prev);
}
.slider::after {
right: 0;
content: attr(data-next);
}
$sliderElement.on('init afterChange', function(e, { $slider }) {
const $active = $slider.find('.slick-active');
$slider.attr({
'data-prev': `prev: ${$active.prev().text() || 'какой-то дефолтный текст'}`,
'data-next': `next: ${$active.next().text() || 'какой-то дефолтный текст'}`,
});
})