YUI 3.x Home -

YUI Library Examples: The YUI Global Object: Multiple Instances

The YUI Global Object: Multiple Instances

This example shows how to work with multiple YUI instances.

Setting up the first YUI Instance

Here we will create our first YUI instance and tell it to load the anim module.

  1. YUI().use('anim', function(Y) {
  2.  
  3. });
YUI().use('anim', function(Y) {
 
});

Using Animation

Now let's setup a simple animation on the Node #demo.

  1. YUI().use('anim', function(Y) {
  2. var anim = new Y.Anim({
  3. node: '#demo',
  4. to: {
  5. height: 50,
  6. width: 150
  7. },
  8. from: {
  9. height: 100,
  10. width: 100
  11. },
  12. direction: 'alternate',
  13. iterations: 30,
  14. duration: .5
  15. });
  16. anim.run();
  17. });
YUI().use('anim', function(Y) {
    var anim = new Y.Anim({
        node: '#demo',
        to: {
            height: 50,
            width: 150
        },
        from: {
            height: 100,
            width: 100
        },
        direction: 'alternate',
        iterations: 30,
        duration: .5
    });
    anim.run();
});

Setting up the second YUI Instance

Here we will create our second YUI instance and tell it to load the dd-drag module.

Since we didn't specify the anim module, we will not have access to it in this instance.

  1. YUI().use('dd-drag', function(Y) {
  2.  
  3. });
YUI().use('dd-drag', function(Y) {
 
});

Making the node draggable

Now let's make the same node draggable (while it's animated).

  1. YUI().use('dd-drag', function(Y) {
  2. var dd = new Y.DD.Drag({
  3. node: '#demo'
  4. });
  5. });
YUI().use('dd-drag', function(Y) {
    var dd = new Y.DD.Drag({
        node: '#demo'
    });
});

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings