简体   繁体   English

如何为YUI3插件/小工具对象分配自定义类

[英]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. 叠加层获取属性中指定的ID。 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. 子类叠加并添加className配置属性。 If you have other customization to do, this is an attractive option. 如果您要进行其他自定义,这是一个有吸引力的选择。
  3. Hook the overlay:render event and attach the class there. 钩住overlay:render事件并将类附加到那里。 Here's a jsfiddle that demonstrates this technique: http://jsfiddle.net/4zN5M/1/ 这是演示此技术的jsfiddle: http : //jsfiddle.net/4zN5M/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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