How do you use the animate() method in jQuery?
<div id="box" style="width:100px;">Box</div>
$('#box').animate({ width: '+=100px', opacity: 0.5 }, 500, function () {
console.log('Done: ' + $(this).css('width'));
});
Console output
Done: 200px
Only numeric properties can be animated (colors need a plugin). See jQuery animate().
Learn more about the similar topics:
| Tutorials |
|---|
| jQuery Effects: hide, show and toggle |
| jQuery Fade and Slide Effects |
| jQuery animate() Method |
| jQuery Method Chaining and Callbacks |
| Exercises & Assignments |
|---|
| Write jQuery code to show and hide a panel with one button |
| Write jQuery code to make a simple accordion |
| Write jQuery code to make simple tabs |