Jump to content
Search Community

Scale a child inside an array?

kabocreative test
Moderator Tag

Go to solution Solved by Carl,

Recommended Posts

Hi!

I've got a pretty simple challenge that's stumped me.. 

 

I've got a series of container divs which include text + image. I want the image to zoom on hover/mousenter, i.e. in CSS:

 

.container:hover img {
  transform: scale(1.1);
}

Where I'm finding this tricky is that it is when the container (parent) is hovered that the img (child) should scale.

 

I've worked out utils.toArray and forEach are the things I want to play with, but I've made a bit of a mess that doesn't work whacking one inside the other:
 

gsap.utils.toArray("#portfolio-scene .container").forEach(blurb => {
  gsap.utils.toArray("#portfolio-scene .container img").forEach(image => {
	let hover = gsap.to(image, {scale: 1.1, duration: 1.5, paused: true, ease: "power1.inOut"});
  	blurb.addEventListener("mouseenter", () => hover.play());
  	blurb.addEventListener("mouseleave", () => hover.reverse());
  })
});

I know it's not right, but I'm not sure what is. Currently if you hover on any container all img's scale.

 

I also tried the following which caused the exact same behaviour:

 

gsap.utils.toArray("#portfolio-scene .container").forEach(blurb => {
  let image = gsap.utils.toArray("#portfolio-scene .container img")
  let hover = gsap.to(image, {scale: 1.1, duration: 1.5, paused: true, ease: "power1.inOut"});
  blurb.addEventListener("mouseenter", () => hover.play());
  blurb.addEventListener("mouseleave", () => hover.reverse());
});


Codepen:



Massive thanks to anyone who can point out where I'm going wrong :)

 

See the Pen ZExVQVL by kabocreative (@kabocreative) on CodePen

Link to comment
Share on other sites

Big thanks Carl! So simple (if you know what you are looking for!) and makes perfect sense. 

 

Thanks also for the direct link to the lesson. I've found the course incredibly helpful! Ran through the SVG modules this week and thoroughly enjoyed having a play! :) I've got some lovely SVGs working on the staging site now ready for launch. Thanks!!

 

 

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...