.tab-content__item {
display: none;
}
.tab-content__item.active {
display: list-item;
}
.tab-header__item.active {
color: red;
}
const headerSelector = '.tab-header__item';
const contentSelector = '.tab-content__item';
const activeClass = 'active';
// делегирование, обработчик клика добавляется один раз для всех хедеров;
// контент, соответствующий нажатому хедеру, определяем через равенство data-атрибутов
document.addEventListener('click', e => {
const header = e.target.closest(headerSelector);
if (header) {
const { tab } = header.dataset;
const toggle = n => n.classList[n.dataset.tab === tab ? 'toggle' : 'remove'](activeClass);
document.querySelectorAll(headerSelector).forEach(toggle);
document.querySelectorAll(contentSelector).forEach(toggle);
}
});
// или, обработчик клика добавляется каждому хедеру индивидуально;
// контент, соответствующий нажатому хедеру, определяем по равенству индексов
const headers = document.querySelectorAll(headerSelector);
const contents = document.querySelectorAll(contentSelector);
headers.forEach(n => n.addEventListener('click', onClick));
function onClick() {
const index = Array.prototype.indexOf.call(headers, this);
const toggle = (n, i) => n.classList[i === index ? 'toggle' : 'remove'](activeClass);
headers.forEach(toggle);
contents.forEach(toggle);
}
i * 4000
на (i * 2 + 1) * 1000
- чтобы таймауты не совпадали <input id="min" type="number" value="25"> -
<input id="max" type="number" value="75">
<div id="range"></div>
const values = {
min: 0,
max: 100,
};
const range = $('#range').ionRangeSlider({
type: 'double',
grid: true,
...values,
onChange(e) {
$('#min').val(e.from);
$('#max').val(e.to);
},
}).data('ionRangeSlider');
$('#min, #max').attr(values).on('input', function() {
const v = [ $('#min').val(), $('#max').val() ]
.sort((a, b) => a - b)
.map(n => Math.max(values.min, Math.min(values.max, +n)));
$('#min').val(v[0]);
$('#max').val(v[1]);
range.update({
from: v[0],
to: v[1],
});
}).trigger('input');
<input id="min" type="number" value="25"> -
<input id="max" type="number" value="75">
<div id="range"></div>
const values = {
min: 0,
max: 100,
};
$('#range').slider({
range: true,
...values,
slide(e, ui) {
$('#min').val(ui.values[0]);
$('#max').val(ui.values[1]);
},
});
$('#min, #max').attr(values).on('input', function() {
const v = [ $('#min').val(), $('#max').val() ]
.sort((a, b) => a - b)
.map(n => Math.max(values.min, Math.min(values.max, +n)));
$('#min').val(v[0]);
$('#max').val(v[1]);
$('#range').slider('values', v);
}).trigger('input');
const reg = new RegExp(`(.+).{${symbolsForHide}}$`);
$('.phone_number')
.attr('data-phone', function() {
return $(this).text()
})
.text((i, text) => text.replace(reg , '$1...'));
const
$this = $(this),
$phone = $this.siblings('.phone_number'),
phone = $phone.data('phone');
$phone.text(phone).attr('href', `tel: ${phone}`);
$this.remove();
:license="{
old_price: 20,
price: 200,
title: 2,
}"
computed: {
brands() {
return [...new Set(this.profiles.map(n => n.brand.name))];
},
},
<option v-for="brand in brands" :value="brand">{{ brand }}</option>
const router = new VueRouter({
routes: [
{ path: '/', component: { template: '<div>Home</div>' } },
{ path: '/foo', component: { template: '<div>Foo</div>' } },
{ path: '/boo', component: { template: '<div>Boo</div>' } },
],
});
new Vue({
router,
el: '#app',
data: () => ({
routeIndex: 0,
}),
created() {
setInterval(() => {
const { routes } = this.$router.options;
this.routeIndex = (this.routeIndex + 1) % routes.length;
this.$router.push(routes[this.routeIndex]);
}, 1000);
},
});
<div id="app">
<router-view></router-view>
</div>
const key = 'prop';
const val = 1;
const result = array.flatMap(n => n.filter(m => m[key] === val));
// или
const result = array.reduce((acc, n) => (
n.forEach(m => m[key] === val && acc.push(m)),
acc
), []);
// или
const result = [];
for (const n of [].concat(...array)) {
if (n[key] === val) {
result[result.length] = n;
}
}
получает следующие аргументы <...> При определении в модуле
state, // при использовании модулей — локальный state модуля getters, // локальные геттеры текущего модуля rootState, // глобальный state rootGetters // все геттеры
$('.slider-nav')
.slick({
slidesToShow: 5,
slidesToScroll: 1,
dots: true,
centerMode: true,
focusOnSelect: true,
variableWidth: true,
})
.on('click', '.slick-slide', function() {
$('.slider-for').slick('slickGoTo', this.dataset.index);
})
.find('.item-nav')
.attr('data-index', i => i);
if (!this.map) {
this.map = DG.map(...);
this.marker = DG.marker(...);
} else {
this.map.panTo(...)
this.marker.setLatLng(...);
}
[...new Set(array.flatMap(n => n.columns).map(n => n.type).filter(n => !defaultTypes.includes(n)))]