PageRenderTime 64ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/README.md

https://gitlab.com/learn-co-curriculum/cssi-3-6-jquery-animation
Markdown | 45 lines | 30 code | 15 blank | 0 comment | 0 complexity | d3ed2e77ba88d42a1c2605b3f0b0977a MD5 | raw file
  1. #Animation with jQuery and CSS
  2. One of the cooler features of jQuery is animation. The concept is pretty simple:
  3. - You have an element with its current style
  4. - You set a target style
  5. - jquery gradually changes the style from one to the other
  6. It turns out there is some somewhat complicated math for the values of the properties as they are changing, but you dont have to worry about that at all. Instead, you describe to jQuery exactly how you want the animation to happen - how long it should take, and what rate the change should happen - and it figures all that out for you.
  7. ### Animation using the animate() Method
  8. The full syntax for the animate() method is below:
  9. `$(selector).animate({params},speed,callback);`
  10. * *params* defines the CSS properties to be animated.
  11. * *speed* is optional and specifies the duration of the effect "slow", "fast", or milliseconds.
  12. * *callback* is an optional function to be executed after the animation completes.
  13. Here's an example:
  14. ```
  15. $('p').animate(
  16. {fontSize: 24},
  17. 1500
  18. )
  19. ```
  20. Over 1500 ms, the font-size in the paragraphs will change from whatever it was to 24.
  21. #### Animation Shortcuts
  22. There are also some convenient shortcut methods for common animations developers use all the time:
  23. - .slideUp() - slide an element up a distance
  24. - .slideDown()
  25. - .fadeIn() - Show an element with a slow fade
  26. - .fadeOut() - Fade out the element
  27. Animation powers all kinds of nice-feeling web experiences - when a page has satisfying button clicks, when elements fade or slide (or both!) nicely onto and off the page - all excellent animation. Animation can be bad too - when the sliding is too slow, or the fades and slides in and out look cartoonish and silly.
  28. As with color, font, position, whitespace, and design generally, there is far more depth to animation than we are going to cover. You can check out [this tutorial](http://www.sitepoint.com/guide-jquery-animate-method/) to learn more. As always, getting good takes practice.
  29. Check the [documentation](https://api.jquery.com/category/effects/) for more examples and explanations.
  30. <p data-visibility='hidden'>View <a href='https://learn.co/lessons/cssi-3.6-jquery-animation' title='Animation with jQuery and CSS'>Animation with jQuery and CSS</a> on Learn.co and start learning to code for free.</p>