JavaScript: Animated UL lists


SUBMITTED BY: Guest

DATE: Feb. 17, 2014, 3:58 p.m.

FORMAT: Text only

SIZE: 4.6 kB

HITS: 678

  1. Description: This jQuery script adds flare to your UL lists, by animating the items into view, one item at a time. You can get each item to slide in from the left, drop in, or even spin before making their way to their destination. It harnesses the power of CSS3 transitions to do its bidding, by animating any defined CSS properties before and after values.
  2. The script lets you choose from 3 display modes- immediately animate the UL list(s) when the page loads, after x seconds, or only when the UL becomes visible on the screen. The default setting is the last one, ensuring the user will always witness your UL lists making their appearance in style!
  3. This script works in all CSS3 capable browsers (IE10+, FF, Chrome etc), and simply does nothing with the UL list for the rest. Cool!
  4. Directions:
  5. Step 1: Add the following code to the <HEAD> section of your page:
  6. <!doctype html>
  7. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  8. <style>
  9. ul.demo1 li{ /* initial CSS for demo 1 (before it's animated) */
  10. opacity: 0; /* animate opacity into view */
  11. left: -100%; /* animate left property into view */
  12. }
  13. ul.demo1-after li{ /* Post CSS for demo 1 (after it's animated). "demo1-after" dynamically added to UL */
  14. opacity: 1;
  15. left: 0;
  16. }
  17. ul.gallery{ /* initial CSS for .gallery */
  18. margin: 0;
  19. padding: 0;
  20. list-style: none;
  21. overflow: hidden;
  22. }
  23. ul.gallery li{ /* initial CSS for .gallery (before it's animated) */
  24. float: left;
  25. width: 190px;
  26. height: 105px;
  27. left: -120%; /* animate left property into view */
  28. opacity: 0;
  29. -moz-transform: rotate(180deg) scale(2); /* animate CSS3 transform into view */
  30. -ms-transform: rotate(180deg) scale(2);
  31. -o-transform: rotate(180deg) scale(2);
  32. -webkit-transform: rotate(180deg) scale(2);
  33. transform: rotate(180deg) scale(2)
  34. }
  35. ul.gallery-after li{ /* Post CSS for .gallery (after it's animated). "gallery-after" dynamically added to UL */
  36. left: 0;
  37. opacity: 1;
  38. -moz-transform: rotate(0deg) scale(1);
  39. -ms-transform: rotate(0deg) scale(1);
  40. -o-transform: rotate(0deg) scale(1);
  41. -webkit-transform: rotate(0deg) scale(1);
  42. transform: rotate(0deg) scale(1)
  43. }
  44. </style>
  45. <!--[if lte IE 9]>
  46. <style>
  47. /* In IE9 or less, ensure UL is always visible */
  48. ul li{
  49. left: 0 !important;
  50. top: 0 !important;
  51. opacity: 1 !important;
  52. }
  53. </style>
  54. <![endif]-->
  55. <script src="jquery.animatedlists.js">
  56. </script>
  57. <script>
  58. jQuery(function($){ // on DOM load
  59. $('ul.demo1').animatelist({pause: 1, postclass: 'demo1-after'})
  60. $('ul.gallery').animatelist({duration: 0.7, postclass: 'gallery-after'})
  61. })
  62. </script>
  63. Download http://www.javascriptkit.com/script/script2/jquery.animatedlists.js (right click and select "Save As"), the external file referenced by the above code.
  64. Step 2: Add the below sample HTML markup to your <BODY>:
  65. <ul class="demo1">
  66. <li><a href="http://www.javascriptkit.com/javatutors/preloadimagesplus.shtml">Preloading images and executing code only after all images have loaded</a></li>
  67. <li><a href="http://www.javascriptkit.com/javatutors/setcss3properties.shtml">Setting CSS3 properties using JavaScript</a></li>
  68. <li><a href="http://www.javascriptkit.com/javatutors/domstorage.shtml">Going beyond cookies- Using DOM sessionStorage and localStorage to persist larger amounts of info</a></li>
  69. <li><a href="http://www.javascriptkit.com/javatutors/createelementcheck.shtml">Using document.createElement() to test for browser support for an element</a></li>
  70. <li><a href="http://www.javascriptkit.com/javatutors/onmousewheel.shtml">The onmousewheel event of JavaScript</a></li>
  71. <li><a href="http://www.javascriptkit.com/javatutors/trycatch.shtml">Handling runtime errors in JavaScript using try/catch/finally</a></li>
  72. <li><a href="http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml">Dynamically loading an external JavaScript or CSS file</a></li>
  73. </ul>
  74. <ul class="gallery">
  75. <li><img src="fusion.jpg" /></li>
  76. <li><img src="fusion2.jpg" /></li>
  77. <li><img src="fusion3.jpg" /></li>
  78. <li><img src="fusion4.jpg" /></li>
  79. <li><img src="fusion5.jpg" /></li>
  80. <li><img src="fusion6.jpg" /></li>
  81. <li><img src="fusion7.jpg" /></li>
  82. <li><img src="fusion8.jpg" /></li>
  83. </ul>

comments powered by Disqus