Затем я решил повторно реализовать это в моем текущем проекте Angular:
Код: Выделить всё
rolling.component.htmlКод: Выделить всё
{{ digit }}
Код: Выделить всё
rolling.component.scssКод: Выделить всё
$size: 30px;
.animated-rolling-number {
position: relative;
height: 10 * $size;
overflow: hidden;
display: flex;
}
.animated-rolling-character {
height: 10 * $size;
display: flex;
flex-direction: column;
transition: margin-top 2s;
font-size: $size;
margin-top: 0; // even removing this doesnt work either
div {
height: $size;
display: flex;
align-items: center;
justify-content: center;
}
}
Код: Выделить всё
rolling.component.tsКод: Выделить всё
import {Component, Input} from '@angular/core';
@Component({
selector: 'rolling-number',
templateUrl: './rolling-number.component.html',
styleUrls: ['./rolling-number.component.scss']
})
export class RollingNumberComponent {
public rollingCharacters: number[] = [];
private _value: number = 0;
private size: number = 30;
@Input()
set value(newValue: number) {
if (newValue !== this._value) {
this._value = newValue;
this.updateRollingCharacters(newValue);
}
}
private updateRollingCharacters(newValue: number) {
this.rollingCharacters = newValue.toString().split('').map(Number);
}
public getMargin(index: number): string {
const currentDigit = this.rollingCharacters[index] || 0;
const marginTop = -(9 - currentDigit) * this.size;
return `${marginTop}px`;
}
}
Однако проблема в том, что когда я пытаюсь каким-либо образом изменить число, добавив setTimeOut или, увеличивая/уменьшая его, смещение поля-верха происходит немедленно, несмотря на то, что я уже определил переход там? Правильно ли я здесь использовал переход или мне нужно использовать его каким-то другим способом?
Подробнее здесь: https://stackoverflow.com/questions/790 ... ork-at-all
Мобильная версия