const { id } = Object.values(CategoryProduct).flat().find(n => n.name === name) || {};
const selector = 'li.my_class a[href="#"]';
.document.querySelectorAll(selector).forEach(function(n) {
n.addEventListener('click', this);
}, e => e.preventDefault());
document.addEventListener('click', e => {
const link = e.target.closest(selector);
if (link) {
e.preventDefault();
}
});
Не могу понять, что в моём коде не так.
function getIndexOfWarmestDay(data){
let max = 0;
resultArr += max;
max = 0;
console.log(resultArr);
console.log
тут надо делать return
.data.map(n => Math.max(...n))
.return createElement('div', {
domProps: {
innerHTML: '<b>hello, world!!</b>',
},
});
getters: {
postsByCatId: ({ posts }) =>
posts.reduce((acc, n) => (
(acc[n.catId] = acc[n.catId] || []).push(n),
acc
), {}),
},
const postsMixin = {
data: () => ({
catId: null,
}),
computed: {
posts() {
return this.$store.getters.postsByCatId[this.catId] || [];
},
},
};
function scrollTracking() {
const wt = $(window).scrollTop();
const wh = $(window).height();
$('#console').html($('.active').get().find(n => {
const et = $(n).offset().top;
const eh = $(n).outerHeight();
return wt > et && wt + wh - eh * 2 <= et + (wh - eh);
}) ? 'Работает' : 'Не работает');
}
[ 1, 2 ]
, например. Или [ 5, 6, 8, 9 ]
.const range = ([...arr]) => arr
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
(n === a[i - 1] + 1) || acc.push([ n ]),
acc[acc.length - 1][1] = n,
acc
), [])
.map(([ a, b ]) => a === b ? a : `${a}-${b}`)
.join(', ');
const range = arr => ''.concat(...arr
.slice()
.sort((a, b) => a - b)
.reduce((acc, n, i, a) => (
n !== a[i - 1] + 1 && acc.push(i ? `, ${n}` : n),
n === a[i - 1] + 1 && n !== a[i + 1] - 1 && acc.push(`-${n}`),
acc
), [])
);
.media
в дополнительный div
, которому задайте стиль:.media > div {
display: flex;
}
не давать снять последний чекбокс
function interval(arr, delay, callback) {
let i = ~-arr.length;
return arr.length
? setInterval(() => callback(arr[i], arr[i = -~i % arr.length]), delay)
: null;
}
// или
function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function step(i) {
timeoutId = setTimeout(() => {
callback(arr[i++], arr[i %= arr.length]);
step(i);
}, delay);
})(arr.length - 1);
return () => clearTimeout(timeoutId);
}
interval(
document.querySelectorAll('.banner-block'),
300,
(prev, curr) => {
prev.classList.remove('active');
curr.classList.add('active');
}
);
interval
, для первой версии передавать этот результат в clearInterval
, а для второй вызвать его. В документации написано, что данные передаваемые через provide/inject от родителя ребенку реактивны.
Note: theprovide
andinject
bindings are NOT reactive.
$('.num').each(function() {
$({ value: 0 }).animate({ value: +$(this).text() }, {
duration: 1000,
easing: 'linear',
step: val => $(this).text(val.toFixed(2)),
});
});
.item
добавить data-атрибуты, указывающие, выбор какого типа осуществляется с помощью кнопок внутри (only
- выбран может быть только один вариант вообще, one
- выбран может быть только один вариант внутри данного .item
, multiple
- можно выбирать произвольное количество вариантов внутри данного .item
):<div class="item" data-type="only">
<h2>Выбрать все категории</h2>
...
</div>
<div class="item" data-type="one">
<h2>Выбрать пол</h2>
...
</div>
<div class="item" data-type="multiple">
<h2>Выбрать тип одежды</h2>
...
</div>
const containerSelector = '.filter';
const itemSelector = `${containerSelector} .item`;
const baseBtnSelector = 'button';
const btnSelector = `${itemSelector} ${baseBtnSelector}`;
const btnOnlySelector = `${itemSelector}[data-type="only"] ${baseBtnSelector}`;
const activeClass = 'active';
document.addEventListener('click', ({ target: t }) => {
const button = t.closest(btnSelector);
if (button) {
const toggle = n => n.classList.toggle(activeClass, n === button);
const item = button.closest(itemSelector);
const { type } = item.dataset;
item
.closest(containerSelector)
.querySelectorAll(type === 'only' ? btnSelector : btnOnlySelector)
.forEach(toggle);
if (type === 'multiple') {
button.classList.toggle(activeClass);
} else if (type === 'one') {
item.querySelectorAll(btnSelector).forEach(toggle);
}
}
});