code0n Posted November 20, 2018 Share Posted November 20, 2018 i am not able to control the css properties for animation using Tweenjs , finding difficulty in adding it. Suggest how could i achieve it. I want to control border radius css property of css. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted November 25, 2018 Share Posted November 25, 2018 https://github.com/tweenjs/tween.js/ Whats the exact problem you're having? The top of the above linked readme shows DOM manipulations, the following snippet makes very minimal changes to that code from the readme. <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/16.3.5/Tween.min.js"></script> </head> <body> <script> var box = document.createElement('div'); box.style.setProperty('background-color', '#008800'); box.style.setProperty('width', '100px'); box.style.setProperty('height', '100px'); box.style.setProperty('border-radius', '0px') document.body.appendChild(box); // Setup the animation loop. function animate(time) { requestAnimationFrame(animate); TWEEN.update(time); } requestAnimationFrame(animate); var coords = { x: 0 }; // Start at (0, 0) var tween = new TWEEN.Tween(coords) // Create a new tween that modifies 'coords'. .to({ x: 100 }, 10000) // Move to (300, 200) in 1 second. .easing(TWEEN.Easing.Quadratic.Out) // Use an easing function to make the animation smooth. .onUpdate(function() { // Called after tween.js updates 'coords'. // Move 'box' to the position described by 'coords' with a CSS translation. // box.style.setProperty('transform', 'translate(' + coords.x + 'px, ' + coords.y + 'px)'); box.style.setProperty('border-radius', coords.x + 'px') }) .start(); // Start the tween immediately. </script> </body> I added the border radius, changed the object from 2d to 1d (border radius is a single value) and updated the update function to alter the border radius property (I also upped the time from the example to 10s which makes it easier to see the change over time). I have limited understanding of Tween.js, but it literally just handles the rate of change over time, you then handle the application of that change. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.