简体   繁体   中英

A-Frame rotate cube dynamically with javascript

i am working a little bit with A-Frame, Socket.io etc.

I want to rotate a cube/box and it works. But just static with a html tag like this:

<a-box position="-1 0.5 -3" rotation="0 0 0" color="#4CC3D9">
        <a-animation id="cubeAnimation"  attribute="rotation" from="0 0 0" to="270 0 0" dur="2000" direction="alternate" begin="playAnimation"></a-animation>
</a-box>

i can call the playAnimation begin function with javascript. But i dont know who to change the to parameters. I want to make a dynamically rotation with javascript or angualarjs.

Maybe someone could help me. Maybe it is possible to set the to attribute via javascript.. i tried a lot of stuff but nothings works..

thanks

okay i found a way. If anyone will have the same problem in the future, this solution works :)

const el = document.createElement('a-animation');
el.setAttribute('from', '0 0 0');
el.setAttribute('to', '360 180 0');
el.setAttribute('id', 'cubeAnimation');
el.setAttribute('attribute', 'rotation');
el.setAttribute('dur', '1000');
el.setAttribute('begin', 'wuerfeln');
cube.appendChild(el);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM