const wrapper = document.querySelector('.block');
const blockSelector = '.block_one';
const activeClass = 'active';
wrapper.addEventListener('mouseover', onHover);
wrapper.addEventListener('mouseout', onHover);
function onHover({ type, target }) {
const block = type === 'mouseover' && target.closest(blockSelector);
this.querySelectorAll(blockSelector).forEach(n => {
n.classList.toggle(activeClass, !!block && n !== block);
});
}
.block:has(.block_one:hover) .block_one:not(:hover) {
/* сюда переносим стили того класса, который через js добавлялся */
}
computed: {
task() {
return new Proxy(this.value, {
set: (target, prop, value) => {
this.$emit('input', { ...target, [prop]: value });
return true;
},
});
},
},
v-model
соответствующих полей ввода):<input type="checkbox" v-model="task.done">
<button v-if="task.done" @click="$emit('delete')">delete</button>
<task-element
v-for="(n, i) in todos"
v-model="todos[i]"
@delete="todos.splice(i, 1)"
></task-element>
document.querySelectorAll('.number').forEach(n => {
n.innerText = n.innerText.replace(/\d+/g, m => (+m).toLocaleString());
});
for (const n of document.getElementsByClassName('number')) {
n.textContent = n.textContent.replace(/\d(?=(\d{3})+(\D|$))/g, '$& ');
}
$headers = array_column($data[0]['pages'], 'name');
$columns = array_column($data[0]['pages'], 'attribute');
$rowCount = max(array_map('count', $columns));
$headersHTML = implode('', array_map(function($n) {
return "<th>$n</th>";
}, $headers));
$rowsHTML = implode('', array_map(function($i) use($columns) {
return "
<tr>".implode('', array_map(function($n) use($i) {
return "<td>".($n[$i] ?? '')."</td>";
}, $columns))."
</tr>";
}, range(0, $rowCount - 1)));
echo "
<table>
<thead>
<tr>$headersHTML</tr>
</thead>
<tbody>$rowsHTML</tbody>
</table>";
fetch('https://api.novaposhta.ua/v2.0/json/', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
modelName: 'Address',
calledMethod: 'getWarehouses',
methodProperties: {
CityName: document.querySelector('.myCityName').textContent,
},
apiKey: '',
}),
})
.then(r => r.json())
.then(r => {
document.querySelector('.mySelect').innerHTML = r.data
.map(n => `<option>${n.Description}</option>`)
.join('');
});
setInterval(tesla.moveRight,30)
setInterval(tesla.moveRight.bind(tesla), 30)
setInterval(() => tesla.moveRight(), 30)
class Car {
...
moveRight = () => {
...
}
}
Библиотеки и фреймворки (React, Vue, Redux...) даются очень тяжело.
Нравится работать с чистым js
используется для получения и установки инлайновых стилей
когда нажимаю повторно чтобы остановить музыку, она не останавливается
const result = arr
.reduce((acc, n, i, a) => (
a[i - 1] !== n && acc.push([ n, 0 ]),
acc[acc.length - 1][1]++,
acc
), [])
.map(([ v, c ]) => c === 1 ? v : Array(c).fill(v));
const result = arr
.reduce((acc, n, i, a) => (
a[i - 1] === n || acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
.map(n => n.length === 1 ? n[0] : n);
const result = arr.reduce((acc, n, i, a) => {
const prev = n === a[i - 1];
const next = n === a[i + 1];
!prev && next && acc.push([]);
(prev || next ? acc[acc.length - 1] : acc).push(n);
return acc;
}, []);
Array.from({ length: 48 }, (n, i) => {
const d = new Date(0, 0, 0, 0, 30 * i);
return d.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
})
u
:preg_match_all("/[а-я]{4,}/ui", $string, $keywords);