有個動畫需求,有幾個div,須要不一樣時,不一樣幅度移動,用了css3+less實現css
使用~``,``內可嵌入js代碼,得到的內容能夠作keyframes 名字,也能夠看成數字參與less的其餘計算,可是得到的內容不能看成class名字vue
.move (@random) { @name: ~`'an-div-move-@{random}'`; @keyframes @name { 0% { transform: translate(0, 0); } 50% { transform: translate(0, @random/1000+.3rem); } 100% { transform: translate(0, 0); } } @s: ~`Math.random()`; animation: @name linear 8s infinite @s*5*1s; } .div-1 { .move( `~Math.round(Math.random()*1000)`); } .div-2 { .move(~`Math.round(Math.random()*1000)`); } .div-3 { .move(~`Math.round(Math.random()*1000)`); }
.div-1 { animation: an-div-move--611 linear 8s infinite 4.82357906s; } @keyframes an-div-move--611 { 0% { transform: translate(0, 0); } 50% { transform: translate(0, -0.311rem); } 100% { transform: translate(0, 0); } } .div-2 { animation: an-div-move-493 linear 8s infinite 1.7538035s; } @keyframes an-div-move-493 { 0% { transform: translate(0, 0); } 50% { transform: translate(0, 0.793rem); } 100% { transform: translate(0, 0); } } .div-3 { animation: an-div-move-557 linear 8s infinite 4.65403445s; } @keyframes an-div-move-557 { 0% { transform: translate(0, 0); } 50% { transform: translate(0, 0.857rem); } 100% { transform: translate(0, 0); } }
在vue-cli中不能使用,直接less編譯能夠,能夠用在webpack本身配置的項目中
可是不知道爲何能夠這麼寫,沒找到官方的說明webpack