dinchu Posted March 13 Share Posted March 13 I have been struggling in creating animations of jpg's in a canvas using GSAP. the only thing i was needing to achieve is a simple animation fadein fadeout of 2 images creating a transition. it works super good an easy outside a canvas. I think with older versions of the library this was possible but not anymore. the fact the new methods: to(), fromTo() take as first parameter a dom element limit the possibility of calculating the animation frame by frame in a canvas. I couldn't find a single example in the docs with a case like mine. The reason why i insist in the use of canvas is the capabilities of a canvas to export a stream of video Link to comment Share on other sites More sharing options...
GSAP Helper Posted March 13 Share Posted March 13 Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: Using a framework/library like React, Vue, Next, etc.? CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: React (please read this article!) Next Svelte Sveltekit Vue Nuxt Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. ✅ Link to comment Share on other sites More sharing options...
dinchu Posted March 13 Author Share Posted March 13 I need to get the values of the opacity in the onUpdate function to pass them to the elements drawed in the canvas. but i don't know how to doit and instead of a smooth transition you just see images going from opacity 0 to 1 without steps every 2 secs (because of the timeouts) See the Pen yLrJGOQ by Pablo-Delgado-the-typescripter (@Pablo-Delgado-the-typescripter) on CodePen Link to comment Share on other sites More sharing options...
Toso Posted March 13 Share Posted March 13 hi @dinchu you can separate the clear and the draw of the canvas inside a ticker func since now you are handling them inside the tween, here is one example with canvas to see the clearing, drawing, and animation of the stars See the Pen yLryMwK by ahmed-attia (@ahmed-attia) on CodePen and another one with pixi https://stackblitz.com/edit/vitejs-vite-7ycqfl?file=main.js&terminal=dev 2 Link to comment Share on other sites More sharing options...
Solution GreenSock Posted March 13 Solution Share Posted March 13 Just to clarify, GSAP is more capable than it has ever been - there was never a time when GSAP just automatically handled <canvas> draw operations for you. It can animate literally any property of any object (not just DOM elements), so you could do it this way: See the Pen OJGXKwZ?editors=0010 by GreenSock (@GreenSock) on CodePen Enjoy! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now