Caspert

Press and hold Tween scale

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 :)

Share this post


Link to post
Share on other sites

Hi @Caspert,

 

What you're looking for in that case are mousedown and mouseup events.

 

 

  • Like 2

Share this post


Link to post
Share on other sites

In the case of the example you gave ... you would need each image in  parent that has overflow: hidden ...

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Hi @Shaun Gorneau

 

Thank you for the fast reply and of course solution. 

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?

Share this post


Link to post
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`.

 

 

 

  • Like 1

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

A little Draggable and ThrowProps can handle most of that slider effect for you. It's similar to one I built a few months ago. Maybe it'll help you get started.

 

 

Happy tweening.

  • Like 3

Share this post


Link to post
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.