0

I need to do this:

  let parallaxBp = 768;

  ScrollTrigger.matchMedia({
    "(min-width: " + parallaxBp + "px)": function() {
      // code
    }
  });

but doesn't work, it says

, expected

So I can't concatenate that string. How can do it?

Fred K
  • 13,249
  • 14
  • 78
  • 103
  • 4
    Put square brackets around the string. See [computed property names](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#computed_property_names). – ASDFGerte Sep 11 '21 at 17:40
  • 1
    the concatenation is working fine. "(min-width: 768px)", but it needs to be encapsulated in square brackets to be used as variable. ["(min-width: " + parallaxBp + "px)"]: function(){} – Gaurav Mithas Sep 11 '21 at 17:50

0 Answers0