Ich habe ein weniger Paket für meine Arbeit schreiben.So erstellen Sie einen zufälligen Keyframes-Namen um weniger das Leerzeichen oder das Anführungszeichen
Einige Code wie folgt:
.goTop(@time:1s,@position:-100%){
\t @random_suffix:`Math.round(Math.random() * 1.0e8)`;
\t @keyframes @random_suffix{
\t \t from{transform:translateY(0);}
\t \t to{transform:translateY(@position);}
\t }
\t animation-name:@random_suffix;
\t animation-duration:@time;
\t animation-timing-function:ease-out;
\t animation-fill-mode:forwards;
}
Dann kann ich es irgendwo verwenden, um auf die ich brauche.
So:
.testbox{
.goTop(1s);
}
Warum sollte ich eine Zufallszahl verwenden?
Denn wenn alle Keyframes sind die gleichen Namen, und der letzte Teil wird den alten Teil überschrieben werden. (Die Argumente sind nicht die gleichen)
Nun wird der Keyframe-Name eine Zufallszahl ist.
Wenn der Keyframe-Name jedoch eine Zahl ist, wird die Animation nicht ausgeführt.
Also ich hoffe, der Name wie goTop_12345678.
Ich versuche, die Zeichenfolge für den Variablennamen zu kontaktieren.
@temp1:goTop_;
@temp2:`Math.round(Math.random() * 1.0e8)`;
@test:@temp1 + @temp2;
// Error
//{"type":"Syntax","message":"Cannot read property 'numerator' of undefined","filename":"input","index":94,"line":4,"callLine":null,"column":0,"extract":["@temp2:goTop_;","@test:@temp1 + @temp2;",""]}
@temp1:'goTop_';
@temp2:`Math.round(Math.random() * 1.0e8)`;
@test:`@{temp1} + @{temp2}`;
//"goTop_12345678"
//It contains the symbol quote "",and the animation will not run.
@temp1:goTop_;
@temp2:@temp1+`Math.round(Math.random() * 1.0e8)`;
@test:@temp2;
//"goTop_ 12345678"
//It contains the space ,and the animation will not run too.
//For the second and third way
//I have try to use replace way to solve it,but I failed.
so, ...
Wie dieses Problem ...
Vielen Dank zu lösen.
@cloudhead
Die Frage ist im Grunde "Wie Zeichenfolge in weniger verketten". [Beispiel] (http://less2css.org/#%7B%22less%22%3A%22%5Cnfoo%20%7B%5Cn%5Ct.go-top()% 3B% 20% 20% 5Cn% 7D% 5Cn% 5Cn.go-top()% 20% 7B% 5Cn% 5Ct% 40Rand% 3A% 20% 60Math.round (Math.Random()% 20 *% 201.0e8)% 60% 3B% 5Cn% 20% 20 % 20% 20% 40name% 3A% 20 ~% 5C% 22go-top-% 40% 7Brandom% 7D% 5C% 22% 3B% 20% 2F% 2F% 20% 3C-% 20here% 20we% 20go% 5Cn% 5Ct% 40Keyframes% 20% 40Name% 20% 7B% 5Cn% 5Ct% 5Ctvon% 20% 7Bbar% 20% 3A1% 7D% 5Cn% 5Ct% 5Ctto% 20% 20% 20% 7Bbaz% 3A% 202% 7D% 5Cn% 5Ct% 7D% 5Cn% 5Chanimationsname% 3A% 20% 40Name% 3B% 5Cn% 7D% 5Cn% 22% 7D). –
Für Ihren speziellen Fall können Sie es machen [nur ...] (http://less2css.org/#%7B%22less%22%3A%22%5Cnfoo%20%7B%5Cn%5Ct.go-top ()% 3B% 20% 20% 5Cn% 7D% 5Cn% 5Cn.go-oben()% 20% 7B% 5Cn% 5Ct% 40Name% 3A% 20 ~% 60'go-top '% 20% 2B% 20Math. Runde (Math.random()% 20 *% 201.0e8)% 60% 3B% 5Cn% 5Ct% 40Keyframes% 20% 40Name% 20% 7B% 5Cn% 5Ct% 5Ctvon% 20% 7Bbar% 20% 3A1% 7D% 5Cn % 5Ct% 5Ctto% 20% 20% 20% 7Bbaz% 3A% 202% 7D% 5Cn% 5Ct% 7D% 5Cn% 5Chanimationsname% 3A% 20% 40Name% 3B% 5Cn% 7D% 5Cn% 22% 7D). Obwohl sie im Allgemeinen den Namen als den Mixin Arg anstelle des zufälligen Hacks liefern (wie es nur Puh ist ...). –
Vielen Dank..du hast Recht. – iRuxu