pulp.morph - Simple Morph Effects API and Demos

API

pulp.morph adds fade and morph effects by extending pulp.node with the following methods. (Assume that the shortcut for pulp.node instances is already set using pulp.ImportShortcuts() or var $ = pulp.node.getInstance;). Demos are below the API information.

fadeIn()

fadeIn() fades an element from transparent to opaque. It can receive 0, one or two arguments. duration is the number of milliseconds over which to perform the animation. When duration is less than 34 (one frame), the number is interpretted as seconds—it is multiplied by 1000. When unspecified, duration defaults to 1000 which is 1000ms. onComplete is the callback to fire when the animation is complete.

  1. $('id').fadeIn(); // duration = 1000ms
  2. $('id').fadeIn(onComplete); // duration = 1000ms
  3. $('id').fadeIn(duration);
  4. $('id').fadeIn(duration, onComplete);

fadeOut()

fadeOut() is the opposite of fadeIn(); it fades an element from opaque to transparent. It can receive 0, one or two arguments just like fadeIn().

  1. $('id').fadeOut(); // duration = 1000ms
  2. $('id').fadeOut(onComplete); // duration = 1000ms
  3. $('id').fadeOut(duration);
  4. $('id').fadeOut(duration, onComplete);

fadeInOut()

fadeInOut() is a concise way to display a user message for a brief period. It fades in an element, pauses then fades out the element. It can receive 0, one or two arguments. delay is the number of milliseconds to pause before fading out the element. delay defaults to 5000ms. onComplete is the callback to fire when the animation is complete. The fade in duration is set to 400ms and the fadeout duration is set to 2500ms—you cannot specify those values.

  1. $('id').fadeInOut(); // delay = 5000ms
  2. $('id').fadeInOut(onComplete); // delay = 5000ms
  3. $('id').fadeInOut(delay);
  4. $('id').fadeInOut(delay, onComplete);

morph()

morph() transforms an element from one style to another. The begin and end style may be an object with style properties (e.g. {width: "400px", color: "#FFBB2E"}), a style string (e.g. "width: 400px; color: #FFBB2E") or a CSS class name. Shorthand styles for border, padding and margin are supported. Color names for common colors are transformed into hex notation. duration and onComplete are optional and work the same way as the fade methods.

  1. $('id').morph(endStyleOrCssClass[,duration[,onComplete]]);
  2. $('id').morph(beginStyleOrCssClass, endStyleOrCssClass[,duration[,onComplete]]);

Demo: Fade In Using fadeIn()

  1. $('fadeIn').fadeIn();

id="fadeIn"

Demo: Fade Out Using fadeOut()

  1. $('fadeOut').fadeOut();

id="fadeOut"

Demo: Notification Popup Using fadeInOut()

  1. $('fadeInOut').fadeInOut(2000);

id="fadeInOut" - May I have your attention please...

Demo: morph() with Style String

  1. var start = 'border:1px solid #aaa; height: 50px; width: 200px; color: #00f;';
  2. var end = 'border:6px solid orange; height: 100px; width: 700px; color: #f00;';
  3. $('morph1').morph(start, end, 1000);

id="morph1"

Demo: morph() with Style Object

  1. var start = {backgroundColor: '#fff', color: '#000', fontSize: '12px'};
  2. var end = {backgroundColor: '#000', color: '#fff', fontSize: '18px'};
  3. $('morph2').morph(start, end, 500);

id="morph2"

Demo: morph() without start Specified

  1. var end = 'border:2px solid gray; height: 200px; width: 200px; font-size: 20px;';
  2. $('morph3').morph(end, 1000);

id="morph3"

Demo: morph() with CSS Classes

  1. <style type="text/css">
  2. .standard {
  3. font-weight: normal;
  4. font-size: 12px;
  5. line-height: 15px;
  6. color: black;
  7. background-color: #ddd;
  8. }
  9. .featured {
  10. font-weight: normal;
  11. font-size: 19px;
  12. line-height: 24px;
  13. color: red;
  14. background-color: #fff;
  15. }
  16. </style>
  17. <script type="text/javascript">
  18. $('morph4').morph('standard', 'featured', 300);
  19. </script>

id="morph4"