const foo = () =>
(
0
+
{
}
)
[
7
]
+
(
0
+
{
}
)
[
2
]
+
(
!
1
+
`
`
)
[
3
]
+
(
0
+
{
}
)
[
7
]
+
(
!
1
+
`
`
)
[
4
]
+
(
!
0
+
`
`
)
[
1
]`
X
`
[
1
]
$('body').html(Array.from({ length: 4 }, (n, i) => `
<svg width="40px" viewBox="0 0 40 40" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle class="border" cx="20" cy="20" r="18"/>
<circle class="fill" cx="20" cy="20" r="18"/>
<text x="12" y="25" class="small">0${i + 1}</text>
</svg>
`));
const $elements = $('.fill');
function animateElem(index) {
$elements.removeClass('animation').eq(index).addClass('animation');
}
$(document).on('animationend', function(e) {
$(e.target).removeClass('animation');
const index = (1 + $elements.index(e.target)) % $elements.length;
animateElem(index);
});
$(document).on('click', 'svg', function(e) {
animateElem($elements.index($('.fill', this)));
});.border {
fill: transparent;
stroke: #ccc;
stroke-width: 2px;
}
.fill {
fill: transparent;
stroke: #000;
stroke-width: 2px;
stroke-dasharray: 120;
stroke-dashoffset: 120;
transform: rotate(-90deg);
transform-origin: center;
}
.animation {
animation: spin 2s both linear;
}
@keyframes spin {
to {
stroke-dashoffset: 1;
}
}
const parentSelectors = [ '.maplabels', '#map' ];
const activeClass = 'active';$(document).on('click', parentSelectors.map(n => `${n} >`).join(','), e => {
const index = $(e.currentTarget).index();
parentSelectors.forEach(n => $(n)
.children()
.removeClass(activeClass)
.eq(index)
.addClass(activeClass)
);
});const parents = parentSelectors.map(n => document.querySelector(n));
document.addEventListener('click', ({ target: t }) => {
const parent = parents.find(n => n !== t && n.contains(t));
if (parent) {
const index = [...parent.children].findIndex(n => n.contains(t));
for (const { children } of parents) {
for (let i = 0; i < children.length; i++) {
children[i].classList.toggle(activeClass, i === index);
}
}
}
});
data: () => ({
file: null,
...<input type="file" accept="image/*" @change="file = $event.target.files[0]">methods: {
uploadAndCreate() {
const data = new FormData;
data.append('name', 'picture');
data.append('file', this.file);
axios.put(... // запрос из uploadImage
axios.post(... // запрос из create
},
...
const nestedVal = {
get(path, root) {
return path.split('.').reduce((p, c) => p[c], root);
},
set(path, root, val) {
path = path.split('.');
const key = path.pop();
nestedVal.get(path.join('.'), root)[key] = val;
}
};
Далее вот так вот например можно вывести данные самой статьи во vuev-for="{description,created_at } in articles" ... {{ description }}
v-for="a in articles" ... {{ a.description }}a.author.name (если конечно, вы насчёт структуры данных не обманываете).v-for="{ author } in articles"author.name будет OK.
При нажатии на svg, event.target присваивается конкретным элементам - картинка внутри svg, текст, фигура итд.
event.target.closest('svg')Допустим я нашел нужный эл-т, и вижу в console.log нужный атрибут, но если вызвать его напрямую, возвращается undefined
card.getAttribute('stroke')onClickFuagra = () => {
this.setState({
strokeFuagra: '...',
});
}
onClickFish = () => {
this.setState({
strokeFish: '...',
});
}<Samy svgXML={fuagra} onClick={this.onClickFuagra}>
...
</Samy>
<Samy svgXML={fish} onClick={this.onClickFish}>
...
</Samy>onClick = e => {
const svg = e.target.closest('svg');
this.setState({
[имя свойства зависит от svg, как определить по кому был клик - думайте сами]: '...',
});
}<div className="banners" onClick={this.onClick}>
...
moment().add(1, 'months').date(10).unix()
onKeyDown = e => {
if (e.key === 'Tab') {
e.preventDefault();
const
input = e.target,
str = input.value,
currPos = input.selectionStart,
wordEnd = str.slice(currPos).search(/[^\w]/);
let pos = str.slice(currPos + wordEnd).search(/[^\s]/);
if (pos) {
pos += currPos + wordEnd;
}
if (pos === currPos) {
pos = 0;
}
input.setSelectionRange(pos, pos);
}
}<input value={this.state.str} onKeyDown={this.onKeyDown} />
<div
*ngFor="let user of users"
[class]="active === user ? 'active' : ''"
(click)="active = user"
>
watch срабатывает тогда когда мне не надо
вотчер возвращает оба одинаковых значения
const random = arr => arr[Math.random() * arr.length | 0];// одно значение
const randomName = random(arr_names);
// или сразу несколько
const randomNames = Array.from(
{ length: 5 },
random.bind(null, arr_names)
);
// работать можно не только с массивами, но и,
// например, со строками, NodeList или HTMLCollection
const randomChar = random('abcdefg');
const randomSpan = random(document.querySelectorAll('span'));
const randomImage = random(document.images);