const items = [
{
name: 'Apple',
dropChance: 0.7
},
{
name: 'Knife',
dropChance: 0.25
},
{
name: 'Spoon',
dropChance: 0.25
},
{
name: 'Ice Cream',
dropChance: 0.1
}
];
const lerp = (min, max, value) => ((1 - value) * min + value * max);
const drop = items => {
const total = items.reduce((accumulator, item) => (accumulator + item.dropChance), 0);
const chance = lerp(0, total, Math.random());
let current = 0;
for (const item of items) {
if (current <= chance && chance < current + item.dropChance) {
return item;
}
current += item.dropChance;
}
};
function listener(event) {
const target = event.target.closest('.app__item');
target.querySelectorAll('.equalizer').forEach(
elem => elem.style.display = 'block'
);
// так как дальнейшие клики будут гонять бесполезный цикл, то лучше отписаться
target.removeEventListener('click', listener);
}
document.querySelectorAll('.app__item').forEach(
item => item.addEventListener('click', listener)
);
querySelectorAll()
сразу по нескольким селекторам.const headerNavMenu = document.querySelector('.headerNav > ul');
const menuToggle = () => {
const value = headerNavMenu.style.display;
headerNavMenu.style.display = (value == 'none' || value == '') ? 'flex' : 'none';
}
[...document.querySelectorAll('.mobileButton, .closeMobileMenu, .headerNav > ul > li')]
.forEach(el => el.addEvenetListener('click', menuToggle));
/wp-content/themes/ПАПКА_ТЕМЫ/img/arrow-left.png
add_action( 'wp_enqueue_scripts', 'action_function_name_7714', 99 );
function action_function_name_7714(){
wp_localize_script( 'jquery', 'mytheme', array(
'template_url' => get_template_directory_uri(),
) );
}
$('.feedback__carousel').owlCarousel({
loop: true,
nav: true,
smartSpeed: 900,
navText: ['<img src="' + mytheme.template_url + '/img/arrow-left.png" alt="Стрелка влево">','<img src="' + mytheme.template_url + '/img/arrow-left.png" alt="Стрелка вправо">'],
});