Potrzebuję wykonać animację na div dla właściwości scaleZ()
i translateZ()
przy użyciu animacji CSS.Animacja CSS dla transformacji nie działa poprawnie podczas korzystania z początkowej klatki kluczowej z wartością macierzy3d
następujący kod działa poprawnie, gdy początkowe i ostatnie klatki kluczowe wartości w animacji dla transform
nieruchomości są w podobnym "format":
- 0% jest
transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
- 100% to
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
console.clear();
document.addEventListener('DOMContentLoaded',() => {
let content1 = document.querySelector('#content1');
var computedTransform = window.getComputedStyle(content1).transform;
console.log(computedTransform);
});
@-webkit-keyframes animation {
0% {
/*works*/
-webkit-transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
/*issue*/
/*transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);*/
}
100% {
-webkit-transform: rotateY(179deg) scaleZ(2) translateZ(200px);
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
}
}
@keyframes animation {
0% {
/*works*/
-webkit-transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
/*issue*/
/*transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);*/
}
100% {
-webkit-transform: rotateY(179deg) scaleZ(2) translateZ(200px);
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
}
}
#content1 {
-webkit-animation: animation 2s;
animation: animation 2s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
/*works*/
-webkit-transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
transform: rotateY(-179deg) scaleZ(2) translateZ(200px);
/*issue*/
/*transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);*/
}
<div id="wrapper1" style="position:fixed; top: 100px; left:300px; perspective: 1000px; width: 250px; height:250px; border: dotted 1px blue">
<div id="content1" style="width: 250px; height:250px; background-color:lightsalmon; opacity:0.2;">
</div>
</div>
Ta sama animacja z transform
dla kluczowej ramki 0% napisany jako matrix3D
wrócił z Window.getComputedStyle()
nie czyni pracę animacji prawidłowo:
- 0% jest
transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
- 100% to
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
console.clear();
document.addEventListener('DOMContentLoaded',() => {
let content1 = document.querySelector('#content1');
var computedTransform = window.getComputedStyle(content1).transform;
console.log(computedTransform);
});
@-webkit-keyframes animation {
0% {
/*works*/
/*transform: rotateY(-179deg) scaleZ(2) translateZ(200px);*/
/*issue*/
-webkit-transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
}
100% {
-webkit-transform: rotateY(179deg) scaleZ(2) translateZ(200px);
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
}
}
@keyframes animation {
0% {
/*works*/
/*transform: rotateY(-179deg) scaleZ(2) translateZ(200px);*/
/*issue*/
-webkit-transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
}
100% {
-webkit-transform: rotateY(179deg) scaleZ(2) translateZ(200px);
transform: rotateY(179deg) scaleZ(2) translateZ(200px);
}
}
#content1 {
-webkit-animation: animation 2s;
animation: animation 2s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
/*works*/
/*transform: rotateY(-179deg) scaleZ(2) translateZ(200px);*/
/*issue*/
-webkit-transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
transform: matrix3d(-0.999848, 0, 0.0174524, 0, 0, 1, 0, 0, -0.0349048, 0, -1.9997, 0, -6.98096, 0, -399.939, 1);
}
<div id="wrapper1" style="position:fixed; top: 100px; left:300px; perspective: 1000px; width: 250px; height:250px; border: dotted 1px blue">
<div id="content1" style="width: 250px; height:250px; background-color:lightsalmon; opacity:0.2;">
</div>
</div>
Z przyczyn technicznych muszę użyć jako klucza ramie 0% wartość dla transformation
właściwie wrócił ze stylu komputerowej w DOM przy użyciu Window.getComputedStyle()
lub inną funkcję, jeśli jest dostępna.
Moje pytania:
- Czy mój kod na drugim przykładzie buggy?
- Czy możesz zaproponować alternatywny sposób uzyskania obliczonej wartości z DOM?
- Czy znasz jakieś błędy związane z wartością zwróconą z
Window.getComputedStyle()
? - Czy znasz jakieś błędy z animacjami CSS i inną "notacją" dla
transform
?
Uwagi: Widzę ten problem w najnowszym Chrome (55.0.2883.87 m) i FireFox (50.1.0).
Wszelkie rozwiązania lub pomysły są mile widziane.
EDIT:
Stworzyłem kilka nowych przykładów (dla Chrome) do dalszego badania.
Zasadniczo dwa przykładem obracać
from rotateY(20deg) to rotateY(90deg)
Korzystanie przekształcać z jednego rodzaju „zapis”, działa zgodnie z oczekiwaniami
pożądany efekt https://jsbin.com/bodaxefake/edit?html,output
Gdy wartości są zamiast podjąć obliczony styl CSS i ponownie zastosowany do animacji za pomocą matrix3d, animacja ma niewielkie zniekształcenie.
Zamiast tego spodziewam się odtworzyć animację, która ma dokładnie taki sam wynik, ponieważ dla mojego zrozumienia, matrix3d z Window.getComputedStyle()
powinien zwrócić tę samą wartość.
Nieprawidłowe działanie https://jsbin.com/luhikahexi/edit?html,output
Odnośnie pkt 3. muszę rozwiązanie, w którym w klatce kluczowej 0% jest zwracana tylko za pomocą komputerowej stylu dom, myślisz, że jest to możliwe do osiągnięcia tego celu? Dziękuję za poświęcony czas. – GibboK
Różnice, które widzisz dla 360deg, są nieistotne (e-16). Jest to po prostu zaokrąglenie błędu podczas konwersji z deg na rad, jak sądzę. Jeśli chodzi o inny problem, spróbuję, ale zauważ, że nadal możesz uzyskać wartość z DOM i właśnie dodałeś dwie rotacje. – vals
Ustawiłem małą sztuczkę, aby uzyskać 0% do obliczonej wartości, nie jestem pewien, czy jest w porządku dla ciebie – vals