Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I animate a scale css property using jquery?

I am trying to have a circle div with the class of "bubble" to pop when a button is clicked using jQuery. I want to get it to appear from nothing and grow to its full size, but I am having trouble getting it to work. heres my code:

HTML Show bubble ... CSS

.bubble {     transform: scale(0); } 

Javascript

 $('button').click(function(){      $('.bubble').animate({transform: "scale(1)"}, 5000, 'linear');  }); 
like image 496
Weylin Wagnon Avatar asked Feb 16 '16 10:02

Weylin Wagnon


People also ask

Can the jQuery animate () method be used to animate any CSS property?

The animate() method is typically used to animate numeric CSS properties, for example, width , height , margin , padding , opacity , top , left , etc. but the non-numeric properties such as color or background-color cannot be animated using the basic jQuery functionality. Note: Not all CSS properties are animatable.

How do you animate in jQuery?

jQuery Animations - The animate() Method The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);

Which of the jQuery method performs a custom animation of a set of CSS properties?

The animate( ) method performs a custom animation of a set of CSS properties.

Is jQuery good for animation?

jQuery was not created for animating objects, so it may be slow and laggy (depending on what and how much you're animating). But scrolling a page with jQuery 's . animate() function for example works very good in most cases.


1 Answers

You can perform the transition using CSS and then just use Javascript as the 'switch' which adds the class to start the animation. Try this:

$('button').click(function() {    $('.bubble').toggleClass('animate');  })
.bubble {    transform: scale(0);    width: 250px;    height: 250px;    border-radius: 50%;    background-color: #C00;    transition: all 5s;  }    .bubble.animate {    transform: scale(1);  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <button>Toggle</button>  <div class='col-lg-2 col-md-2 well bubble'></div>
like image 64
Rory McCrossan Avatar answered Sep 24 '22 02:09

Rory McCrossan