const options = [
[ 'hello, world!!', 'fuck the world', 'fuck everything' ],
500,
(elem => item => elem.textContent = item)
(document.querySelector('.slide-words')),
];
function interval(arr, delay, callback) {
let i = -1;
return arr.length
? setInterval(() => callback(arr[i = -~i % arr.length]), delay)
: null;
}
const intervalId = interval(...options);
// надо остановить, делаем так: clearInterval(intervalId);
function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function next(i) {
timeoutId = setTimeout(() => {
callback(arr[i]);
next((i + 1) % arr.length);
}, delay);
})(0);
return () => clearTimeout(timeoutId);
}
const stop = interval.apply(null, options);
// надо остановить, делаем так: stop();
parseInt('')
будет NaN
.parseInt($(this).val())
на parseInt($(this).val()) || 0
. <span>hello, world!!... fuck the world... fuck everything</span>
body {
margin: 0;
background: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
span {
color: red;
font-size: 24px;
font-family: monospace;
}
.xxx {
display: inline-block;
min-width: 10px;
transition: all 0.2s;
transform: scale(1);
}
.hidden {
opacity: 0;
transform: scale(30);
}
function show(el) {
el.innerHTML = Array
.from(el.innerText, n => `<span class="xxx hidden">${n}</span>`)
.join('');
el.querySelectorAll('span').forEach((n, i) => {
setTimeout(() => n.classList.remove('hidden'), 100 * i);
});
}
show(document.querySelector('span'));
const getValue = el => el.textContent.match(/"(.*?)"/)[1];
// или
const getValue = ({ innerText: t }) =>
JSON.parse(t.slice(t.indexOf('['), -~t.indexOf(']'))).shift();
document.querySelectorAll('li button').forEach(function(n) {
n.addEventListener('click', this);
}, e => console.log(getValue(e.target)));
document.querySelector('ul').addEventListener('click', e => {
if (e.target.tagName === 'BUTTON') {
console.log(getValue(e.target));
}
});
data: () => ({
items: Array(10).fill(null),
...
<ul>
<li v-for="(n, i) in items" :style="index < i || { color: n }">
{{ i }}
</li>
</ul>
methods: {
next(color) {
const { index, items } = this;
this.index = index === items.length - 1 ? 0 : index + 1;
items.splice(this.index, 1, color);
},
...
data: () => ({
colors: [ 'red', 'lime', 'blue', 'orange', 'magenta', 'aqua', 'yellow' ],
...
<button v-for="c in colors" @click="next(c)">{{ c }}</button>
headerObj.offsetTop
const frame = document.getElementsByTagName('iframe')[0];
$data = array_reduce(explode('/', $str), function($acc, $n) {
list($key, $values) = explode('-is-', $n);
$acc[$key] = explode('-or-', $values);
return $acc;
}, []);