$ids = explode(',', $arr['ids']);
$newArr = array_map(function($n, $i) use($arr) {
return [ $n, $arr['src'][$i] ];
}, $ids, array_keys($ids));
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<div id="app" @dragover.prevent="">
<button v-if="done" @click="init">ещё раз</button>
<div v-else>
<div class="questions">
<div
v-for="n in questions"
:class="[ 'card', { hidden: n.done } ]"
draggable="true"
@dragstart="onDragStart($event, n)"
>{{ n.question }}</div>
</div>
<div class="answers">
<div
v-for="n in answers"
:class="[ 'card', { hidden: n.done } ]"
@drop="onDrop(n)"
>{{ n.answer }}</div>
</div>
</div>
</div>
$side: 75px;
.questions,
.answers {
width: $side * 3;
height: $side * 3;
margin: 10px;
display: inline-block;
}
.card {
display: inline-flex;
justify-content: center;
align-items: center;
border: 1px solid silver;
box-sizing: border-box;
width: $side;
height: $side;
background: red;
color: white;
font-weight: bold;
font-family: monospace;
}
.hidden {
visibility: hidden;
}
new Vue({
el: '#app',
data: () => ({
dragged: null,
items: [
{ question: '2 x 2', answer: 4 },
{ question: '5 x 6', answer: 30 },
{ question: '7 x 7', answer: 49 },
{ question: '8 x 4', answer: 32 },
{ question: '7 x 5', answer: 35 },
{ question: '6 x 9', answer: 54 },
{ question: '9 x 8', answer: 72 },
{ question: '6 x 8', answer: 48 },
{ question: '9 x 7', answer: 63 },
].map(n => (n.done = false, n)),
questions: [],
answers: [],
}),
computed: {
done() {
return this.items.every(n => n.done);
},
},
methods: {
onDragStart(e, item) {
this.dragged = item;
},
onDrop(item) {
if (item === this.dragged) {
item.done = true;
} else {
alert('Ты дурак, да?');
}
},
init() {
const { items } = this;
items.forEach(n => n.done = false);
this.questions = [...this.items].sort(() => 0.5 - Math.random());
this.answers = [...this.items].sort(() => 0.5 - Math.random());
},
},
created() {
this.init();
document.addEventListener('dragend', () => this.dragged = null);
},
});
function openCity(e, city) {
document.querySelectorAll('.tablink').forEach(n => {
n.classList.toggle('active', city === 'All' || n === e.target);
});
document.querySelectorAll('.tabcontent').forEach(n => {
n.style.display = city === 'All' || n.id === city ? 'block' : 'none';
});
}
h1 {
font-size: var(--h1-font-size);
}
<input v-model="fontSize" type="range">
<h1>hello, world!!</h1>
data: () => ({
fontSize: 24,
}),
mounted() {
this.$watch(
'fontSize',
val => this.$el.style.setProperty('--h1-font-size', `${val}px`),
{ immediate: true }
);
},
document.querySelectorAll('.number').forEach(number => {
const top = number.getBoundingClientRect().top;
window.addEventListener('scroll', function onScroll() {
if (window.pageYOffset > top - window.innerHeight / 2) {
this.removeEventListener('scroll', onScroll);
let start = +number.innerHTML;
const interval = setInterval(function() {
number.innerHTML = ++start;
if (start >= number.dataset.max) {
clearInterval(interval);
}
}, 5);
}
});
});
$(document).wheel(
var item = $('#time'); if (e.deltaY > 0) item.scrollLeft += 100;
$(document).on('wheel', function(e) {
$('#time')[0].scrollLeft += e.originalEvent.deltaY > 0 ? 100 : -100;
// или
$('#time').get(0).scrollLeft += [ -100, 100 ][+(e.originalEvent.deltaY > 0)];
// или
$('#time').prop('scrollLeft', (i, val) => val + 100 * Math.sign(e.originalEvent.deltaY));
});
typeof
:const strings = arr.filter(n => typeof n === 'string');
const numbers = arr.filter(n => typeof n === 'number');
const booleans = arr.filter(n => typeof n === 'boolean');
const strings = arr.filter(n => n === `${n}`);
const numbers = arr.filter(n => n === +n); // в отличие от typeof, отбрасывает NaN
const booleans = arr.filter(n => n === !!n);
const groupedByType = arr.reduce((acc, n) => {
const type = n == null ? `${n}` : n.constructor.name.toLowerCase();
(acc[type] = acc[type] || []).push(n);
return acc;
}, {});
const strings = groupedByType.string;
const containerSelector = 'ul';
const itemSelector = 'li';
const activeClass = 'active';
const $containers = $(containerSelector).on('click', itemSelector, function(e) {
const index = $(itemSelector, e.delegateTarget).index(this);
$containers.find(`${itemSelector}.${activeClass}`).removeClass(activeClass);
$containers.find(`${itemSelector}:eq(${index})`).addClass(activeClass);
});
const containers = document.querySelectorAll(containerSelector);
containers.forEach(n => n.addEventListener('click', onClick));
function onClick(e) {
const item = e.target.closest(itemSelector);
if (item) {
const items = this.querySelectorAll(itemSelector);
const index = Array.prototype.indexOf.call(items, item);
containers.forEach(container => {
container.querySelectorAll(itemSelector).forEach((n, i) => {
n.classList.toggle(activeClass, i === index);
})
});
}
}