Jump to content
Search Community

OSUblake last won the day on September 16 2023

OSUblake had the most liked content!

OSUblake

Moderators
  • Posts

    9,196
  • Joined

  • Last visited

  • Days Won

    708

Posts posted by OSUblake

  1. 10 minutes ago, Shaun Gorneau said:

    There are quite a few ways to go about this ... ultimately what you want to do is not run your GSAP code on pages where it's not called for.

     

    Sorry, WordPress n00b here. Isn't there a way to not load the file to begin with?

     

  2. A way to do that more like how Vue handles refs. If a ref attribute appears more than once, it gets added to an array.

     

    Ex HTML:

    <div ref="container">
      <div ref="box"></div>
      <div ref="box"></div>
      <div ref="box"></div>
    </div>

     

    BaseElement:

    class BaseElement extends HTMLElement {
      
      select(selector) {
        return this.shadowRoot.querySelectorAll(selector);
      }  
    
      createRefs() {
        const $ = this.$ = {};
        for (const node of this.shadowRoot.querySelectorAll("[ref]")) {
          const id = node.getAttribute("ref");
          
          if (!$[id]) {
            $[id] = node;
          } else {
            if (Array.isArray($[id])) {
              $[id].push(node);
            } else {
              const list = [];
              list.push($[id], node);
              $[id] = list;
            }
          }
        }
      }
    }

     

    Ex JS:

    class MyComponenet extends BaseElement {
    
      connectedCallback() {
        this.createRefs();
        
        gsap.to(this.$.container, {
          x: 100
        });
        
        gsap.to(this.$.box, {
          scale: 0.5
        });
      }
    }

     

     

    • Like 2
  3. What do you think the API should look like? @GreenSock I think something like this would also be a nice addition, especially for people who use React, Vue, Angular. That way they wouldn't have to create a bunch of refs.

     

    But here is how I've handled that in web components. I extend a "BaseElement" class with some extra methods on it. If you're using a library like LitElement, you could do the same thing.

     

    class BaseElement extends HTMLElement {
      
      select(selector) {
        return this.shadowRoot.querySelectorAll(selector);
      }  
    
      createIdCache() {
        this.$ = {};
        for (const node of this.shadowRoot.querySelectorAll("[id]")) {
          this.$[node.id] = node;
        }
      }
    }

     

    So you would call createIdCache after the DOM is available, like in a connected callback. That will make any elements with an id available on the $ object. Or you could just use the select method.

     

    Ex HTML:

    <div id="container">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>

     

    Ex JS:

    class MyComponenet extends BaseElement {
    
      connectedCallback() {
        this.createIdCache();
        
        gsap.to(this.$.container, {
          x: 100
        });
        
        gsap.to(this.select(".box"), {
          scale: 0.5
        });
      }
    }

     

     

    • Like 1
  4. 20 minutes ago, JimmyK said:

    Sometimes it pauses the video randomly

     

    Then maybe it's buffering. The canplaythrough event is just an estimate. You might need to download the video. Google how to create a BLOB and use that as a video source.

     

    But video is super complicated, and well beyond the scope of this forum. Here's a good place to start learning about all the different properties and events available.

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

     

     

    • Like 1
  5. 10 hours ago, Rodrigo said:

    Although in my list you're our Canvas/PIXI/WebGL wizard and also on other categories as well :D:D:D

     

    I originally made that ripple/wave animation in Pixi, but then I stumbled across a site that showed how SVG filters work basically the same, so it was pretty easy to convert.

     

    http://srufaculty.sru.edu/david.dailey/svg/SVGOpen2010/Filters2.htm

    http://srufaculty.sru.edu/david.dailey/svg/newstuff/Newlist.htm

    http://srufaculty.sru.edu/david.dailey/svg/texture/texturepage.htm

     

     

    • Like 4
  6. 2 hours ago, Alixsep said:

    i will be happy if you explain what is going on with refs in array and gsap.

     

    What are you trying to figure out? If you want to animate an list of elements, gsap needs an array or a nodelist.

    gsap.to([element1, element2, element3], {
      x: 100
    });

     

    Push will just keep adding to that list, so you end up with something like this.

    gsap.to([element1, element2, element3, element1, element2, element3,element1, element2, element3], {
      x: 100
    });

     

    2 hours ago, Alixsep said:

    Uhh, as i asked ... why is there so many useEffects in that tutorial?????? none of them has a dependency for useEffect :

     

    You can ask the author. It's not necessary. Maybe they did it for clarity. 🤷‍♂️

     

     

    • Like 1
  7. 10 minutes ago, ferriss said:

    Regards to the .matchMedia(), are you saying I can do it like this:

     

    Yep. Did you look at the examples in the docs? That's pretty much the format they all use.

    https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.matchMedia()

     

    12 minutes ago, ferriss said:

    or the other question was, is there a property to use within the animation.

     

    No that's not possible, but like I said earlier, you can put any code you want inside the matchMedia functions.

     

    • Like 1
  8. Sorry, I still don't quite understand what you're asking. You can put whatever code you want into the matchMedia functions. Can you please put what you're trying to achieve into a demo?

     

    49 minutes ago, ferriss said:

    Yes, I'm aware of JS media queries, but I then didn't want to add in resize debouce as I was hoping GSAP had this in-build so you can resize the browser and it'll degrade without refreshing.

     

    Media query events don't fire on resize, they fire on media query change events, so trying to debounce them is pointless.

     

    • Like 1
  9. 12 hours ago, didkumi said:

    Also, the project is potentially going to grow in size and I was wondering if the set up I currently have is the right way to go...

     

    I would say that you should always use refs instead of selector strings, otherwise you'll quickly run into conflicts with other components that have same ids/class names.

     

    12 hours ago, didkumi said:

    I plan to use d3 functions at some point as well.. 

     

    Which ones? You might be surprised how much gsap can do.

    https://greensock.com/docs/v3/GSAP/UtilityMethods

     

    const posX = d3.scaleLinear()
            .domain([0, 100])
            .range([0, this.viewport.clientWidth]);
    
    // same as this
    const posX = gsap.utils.mapRange(0, 100, 0, this.viewport.clientWidth);

     

    Or just using the plain DOM/SVG APIs.

    d3.select(chart).attr(
          "viewBox",
          `0 0 ${chart.clientWidth} ${chart.clientHeight}`
        );
    
    // same as this...
    chart.setAttribute(`0 0 ${chart.clientWidth} ${chart.clientHeight}`);

     

    • Like 1
  10. That's pretty new. I've known about it, but I don't think I've ever used it....

    transform-box: fill-box;

     

    Back in the day you had to put in the x and y coordinates for the origin to rotate around.

    <rect x="145" y="100" width="30" height="30" transform="rotate(45 145 100)" />

     

     

    • Like 2
  11. @GreenSock would have to answer why GSAP defaults to the top-left of the element instead of the center, but I'm guessing it's because the smooth origin feature came later. If you've worked with complicated transforms before, like with canvas, you will know that changing the transform origin can cause the element position to change.

     

    • Like 1
  12. Well, the only way to make it download faster is to have a faster internet connection. The best thing to do is to make sure your server is allowing those images to be cached so the user doesn't have redownload them again on subsequent page visits.

     

    Another option would be to use video instead of images. You should be able to set the playhead of the video using ScrollTrigger.

×
×
  • Create New...