props: [ 'start', 'end', 'title', 'delay' ],
data: () => ({
val: null,
}),
created() {
this.val = this.start;
const interval = setInterval(() => {
if (++this.val >= this.end) {
clearInterval(interval);
}
}, this.delay);
},
<div>
<h3>{{ title }}</h3>
<div>{{ val }}</div>
</div>
data: () => ({
counters: [
{ start: -20, end: 69, title: 'hello, world!!', delay: 40 },
{ start: 0, end: 187, title: 'fuck the world', delay: 45 },
{ start: 400, end: 666, title: 'fuck everything', delay: 20 },
],
}),
<v-counter
v-for="n in counters"
v-bind="n"
/>
data: () => ({
width: 0,
}),
computed: {
itemSize() {
return this.width > 700 ? 46 : 56;
},
},
methods: {
onResize() {
this.width = window.innerWidth;
},
},
created() {
this.onResize();
window.addEventListener('resize', this.onResize);
},
beforeDestroy() {
window.removeEventListener('resize', this.onResize);
},
// или
data: () => ({
itemSize: null,
}),
created() {
const mql = window.matchMedia('(max-width: 700px)');
const onChange = () => this.itemSize = mql.matches ? 56 : 46;
onChange();
mql.addEventListener('change', onChange);
this.$on('hook:beforeDestroy', () => mql.removeEventListener('change', onChange));
},
:item-size="itemSize"
const ceil = (value, precision) => Math.ceil(value / precision) * precision;
const values = [ 1, 2, 3, 163, 200.001, 99.999 ];
values.map(n => ceil(n, 1)); // [ 1, 2, 3, 163, 201, 100 ]
values.map(n => ceil(n, 10)); // [ 10, 10, 10, 170, 210, 100 ]
values.map(n => ceil(n, 5)); // [ 5, 5, 5, 165, 205, 100 ]
class App extends React.Component {
state = {
items: [
{ id: 69, text: 'hello, world!!' },
{ id: 187, text: 'fuck the world' },
{ id: 666, text: 'fuck everything' },
],
active: null,
}
onClick = e => {
this.setState({
active: +e.target.dataset.index,
});
}
render() {
const { items, active } = this.state;
return (
<div>
{items.map((n, i) => (
<div
key={n.id}
data-index={i}
className={i === active ? 'active' : ''}
onClick={this.onClick}
>{n.text}</div>
))}
</div>
);
}
}
function findN([...arr]) {
const index = arr.sort((a, b) => a - b).findIndex((n, i) => i !== ~-n);
return -~index || -~arr.length;
}
Желательно, чтобы вычислительная сложность была O(n)
const findN = arr => -~arr
.reduce((acc, n) => (acc[~-n] = !1, acc), Array(-~arr.length).fill(!0))
.findIndex(Boolean);
const findN = arr =>
arr.reduce((acc, n) => acc - n, (arr.length + 2) * (arr.length + 1) / 2);
const findN = arr =>
arr.reduce((acc, n, i) => acc ^ n ^ -~i, -~arr.length);
const Header = ({ Top }) => (
<div className="navHeader">
<Top />
</div>
);
...
<Header Top={Top} />
class TabContent extends React.Component {
render() {
const { title, content } = this.props;
return (
<div className="tabcontent">
<h3>{title}</h3>
<p>{content}</p>
</div>
);
}
}
class Tabs extends React.Component {
state = {
active: null,
}
openTab = e => this.setState({
active: +e.target.dataset.index,
});
render() {
const { items } = this.props;
const { active } = this.state;
return (
<div>
<div className="tab">
{items.map((n, i) => (
<button
className={`tablinks ${i === active ? 'active' : ''}`}
onClick={this.openTab}
data-index={i}
>{n.title}</button>
))}
</div>
{items[active] && <TabContent {...items[active]} />}
</div>
);
}
}
const swiperOptions = {
...
on: {
'init resize slideChangeTransitionStart'() {
$('.swiper-pagination').css({
top: $('.swiper-slide-active .head').height() + 30, /* или 40, или 50, или...
* на ваше усмотрение, это чтобы
* пагинация была чуть ниже заголовка,
* а не залезала на него
*/
});
},
},
};
options: {
animation: {
onComplete() {
const { ctx, data, chart } = this;
ctx.fillStyle = 'red';
ctx.textAlign = 'center';
data.datasets.forEach((d, index) => {
chart.controller.getDatasetMeta(index).data.forEach((n, i) => {
ctx.fillText(d.data[i], n._model.x, n._model.y - 10);
});
});
},
},
},
Как сделать, чтобы подписи осей были ниже
options: {
scales: {
xAxes: [ {
ticks: {
padding: тут типа число должно быть,
...
Как сделать, чтобы было не 1000000, а 1 000 000
options: {
scales: {
yAxes: [ {
ticks: {
callback: val => val.toLocaleString(),
...
Снизу подписи начинают идти через 1(происходит это из-за длинного описания), можно ли насильно заставить, чтоб выводились все описания?
autoSkip: false
в настройки подписей.Можно ли первой подписи задать к примеру красный цвет, а остальным уже зеленый?
options: {
scales: {
x: {
ticks: {
color: ({ index }) => index === 0 ? 'red' : 'green',
},
},
},
},
<div class="angle">
<div class="angle-input">
<div class="angle-input-arrow"></div>
</div>
<input type="number" min="0" max="360" value="0">
</div>
.angle {
display: inline-flex;
align-items: center;
border: 1px solid silver;
padding: 5px;
}
.angle-input {
display: inline-flex;
justify-content: center;
border: 1px solid black;
border-radius: 50%;
width: 50px;
height: 50px;
margin-right: 10px;
}
.angle-input-arrow {
height: 50%;
border: 1px solid black;
transform-origin: 50% 100%;
box-sizing: border-box;
pointer-events: none;
}
document.querySelector('.angle input').addEventListener('input', function(e) {
const arrow = this.closest('.angle').querySelector('.angle-input-arrow');
arrow.style.transform = `rotate(${e.target.value}deg)`;
});
const angleInput = document.querySelector('.angle-input');
angleInput.addEventListener('mousedown', onAngleInput);
angleInput.addEventListener('mousemove', onAngleInput);
function onAngleInput(e) {
if (e.buttons === 1) {
const {
offsetX: x, offsetY: y,
target: t,
target: { offsetWidth: w, offsetHeight: h }
} = e;
const deg = (450 + (Math.atan2(y - h / 2, x - w / 2) * (180 / Math.PI) | 0)) % 360;
t.querySelector('.angle-input-arrow').style = `transform: rotate(${deg}deg)`;
t.closest('.angle').querySelector('input').value = deg;
}
}
const data = new FormData();
data.append('sampleFile', this.file);
fetch('http://localhost:3000/upload/', {
method: 'post',
body: data,
})
@change="submitFile($event.target.files[0])"
methods: {
submitFile(file) {
...