<div id="images">
<img src="https://placehold.co/200x200/FF0000/FFFFFF/png">
<img src="https://placehold.co/200x200/00FF00/000000/png">
<img src="https://placehold.co/200x200/0000FF/FFFFFF/png">
</div>
#images img {
transition: transform 0.7s;
}
.rotate {
transform: rotateY(180deg);
}
const toggleRotate = el => el.classList.toggle('rotate');
document.querySelectorAll('#images img').forEach((n, i) => {
setTimeout(setInterval, 300 * i, toggleRotate, 2000, n);
});
#images img {
animation: rotate 4s infinite;
}
#images img:nth-child(1) { animation-delay: 0s; }
#images img:nth-child(2) { animation-delay: 0.3s; }
#images img:nth-child(3) { animation-delay: 0.6s; }
@keyframes rotate {
0%, 75%, 100% {
transform: rotateY(0deg);
}
25%, 50% {
transform: rotateY(180deg);
}
}
messages.sort((a, b) => {
[ a, b ] = [ a, b ].map(n => sortableLanguages.indexOf(n.language));
return a === -1 ? 1 : b === -1 ? -1 : a - b;
});
const sorted = (arr, key) => arr
.map(n => [ n, key(n) ])
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
const order = Object.fromEntries(sortableLanguages.map((n, i) => [ n, i + 1 ]));
const sortedMessages = sorted(messages, n => order[n.language] || Number.MAX_SAFE_INTEGER);
// или
function sorted(arr, order, key) {
const ordered = new Map(order.map(n => [ n, [] ]));
const unordered = [];
arr.forEach(n => (ordered.get(key(n)) || unordered).push(n));
return [].concat(...ordered.values(), unordered);
}
const sortedMessages = sorted(messages, sortableLanguages, n => n.language);
const buttonSelector = '.one';
const contentSelector = '.two';
const className = 'three';
document.querySelector(buttonSelector).addEventListener('click', () => {
document.querySelector(contentSelector).classList.toggle(className);
});
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
const index = [...document.querySelectorAll(buttonSelector)].indexOf(button);
document.querySelectorAll(contentSelector)[index].classList.toggle(className);
}
});
// или
const buttons = document.querySelectorAll(buttonSelector);
const contents = document.querySelectorAll(contentSelector);
buttons.forEach(n => n.addEventListener('click', onClick));
function onClick(e) {
const index = Array.prototype.indexOf.call(buttons, e.currentTarget);
contents[index].classList.toggle(className);
}
function App() {
const [ text, setText ] = React.useState('');
const append = e => setText(text + e.target.textContent);
const clear = () => setText('');
return (<>
<div className="row">
<textarea value={text} readOnly />
</div>
<div className="row">
{Array.from({ length: 10 }, (_, i) => (
<button onClick={append}>{i}</button>
))}
</div>
<div className="row">
<button onClick={clear}>clear</button>
</div>
</>);
}
.row {
display: flex;
justify-content: center;
padding: 5px;
gap: 5px;
}
for (let i = 0; i < password.length; i + 1) {
если запустить код то страница крашнется, codesandbox на счет этого говорит что циклов слишком много
i + 1
- счётчик не меняет своего значения, цикл получается бесконечным.i += 1
или i++
.return pass;
return text
. const mustStay = arr => arr.some(n => n !== '');
const newArr = arr.filter(mustStay);
for (let i = arr.length; i--;) {
if (!mustStay(arr[i])) {
for (let j = i; ++j < arr.length; arr[j - 1] = arr[j]) ;
arr.pop();
}
}
// или
arr.reduceRight((_, n, i, a) => mustStay(n) || a.splice(i, 1), null);
// или
arr.splice(0, arr.length, ...arr.filter(mustStay));
// или
arr.length -= arr.reduce((acc, n, i, a) => (
a[i - acc] = n,
acc + !mustStay(n)
), 0);
usort($variants, function($a, $b) {
return strcmp($a->name, $b->name);
});
[...divs.keys()].forEach(i => console.log(i));
// или
console.log(Array.from(divs.keys(), i => i * 100));
// или
for (const i of divs.keys()) {
console.log(i);
}
$unique = [];
foreach ($arr as $n) {
$unique[$n->name] = $n;
}
$unique = array_values($unique);
const attrName = 'data-i';
const attrValues = [ 'qwe', 'asd', 'zxc' ];
const className = 'класс';
document
.querySelectorAll(attrValues.map(n => `[${attrName}="${n}"]`))
.forEach(n => n.classList.add(className));
for (const n of document.querySelectorAll(`[${attrName}]`)) {
n.classList.toggle(className, attrValues.includes(n.getAttribute(attrName)));
}
почему вот такой код не работает
onLoad={(inst)=>{return inst.events.add('click', clickOnMap)}}
instanceRef={inst => inst.events.add('click', clickOnMap)}
onClick={clickOnMap}
на JS...
document.querySelectorAll('.scroll_list li').forEach(n => {
n.innerHTML = n.textContent.replace(/\d+ шт./, '<span>$&</span>');
});
// или
for (const n of document.querySelector('.scroll_list').children) {
n.innerHTML = n.innerText.replace(/\S+ \S+$/, m => `<span>${m}</span>`);
}
...или PHP
span
создавался сразу.