Jump to content
Search Community

Press and hold Tween scale

Caspert test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi all,

 

I am trying to create a scale animation on click and holding that click. What I would like to achieve is when clicking on an element and holding that click, the image inside will be animation the scale property till it's 2.0. By releasing the click, it will animate back to default scale (1.0).

 

I came with the following code, but doesn't know what the next step is to get the effect I mentioned before.

 

var image = $('img');

		$('li').click(function() {
			TweenMax.to(image, .6, {
				scale: 1.05,
				ease: "smoothInOut",
				onComplete: function() {
					
					TweenMax.to(image, .4, {
						scale: 1,
						ease: "smoothInOut"
					});
				}
			});
		});

 

It's inspired by the following site at the 5th section (the slider).

 

Hope someone can help me a little bit :)

Link to comment
Share on other sites

4 minutes ago, Caspert said:

The only thing is it will sometimes freeze on zoom in and will not going back to the default size. Do you know what it is?

 

That has to do with the drag event. If you put draggable="false" on each image, it will prevent that from interrupting the mouseup event. Every browser and version I can think of supports draggable. But, for the rare case one does not, as a fallback, add the `dragend` event listener to do that same as `mouseup`.

 

See the Pen MxJPNO by sgorneau (@sgorneau) on CodePen

 

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, Caspert said:

Thanks for the updated codepen and answer. Maybe you know if this is made with Greensock: https://www.everest.agency/work/1/signal-snowboards. When scrolling to the 5th section, there is a slider that snaps and has a nice smooth transition. Do you know how this is made? Thanks in advance.

 

 

Doesn't appear to be ... but GSAP is certainly capable of handling the tweened aspects of that site.

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...