简体   繁体   中英

How do I assign custom classes to YUI3 plugin/widget objects

Consider the following code.

var overlay = new Y.Overlay({
                    id:'tooltip-tag',
                    bodyContent:"Loading.....",
                    xy:[e.target.getX(),e.target.getY()+30]
                });

The overlay gets the id as given in attributes. But what if I want to add a class ?

IS there something like:

var overlay = new Y.Overlay({
                    **class:'tooltip-tag'**,
                    bodyContent:"Loading.....",
                    xy:[e.target.getX(),e.target.getY()+30]
                });

No. Here are three ways to do what you want:

  1. Add the class in your markup. I'm guessing this isn't what you want.
  2. Subclass Overlay and add a className config attribute. If you have other customization to do, this is an attractive option.
  3. Hook the overlay:render event and attach the class there. Here's a jsfiddle that demonstrates this technique: http://jsfiddle.net/4zN5M/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM