如何将自定义图标添加到标准 jQuery UI 主题?
问题描述:
使用标准图标集中可用的图标之一很容易:
It is easy to use one of the icons available from the standard icon set:
$("#myButton").button({icons: {primary: "ui-icon-locked"}});
但是如果我想添加一个不属于框架图标集的我自己的图标怎么办?
But what if I want to add one of my own icons that is not part of the framework icon set?
我认为这就像为它提供带有背景图像的自己的 CSS 类一样简单,但这行不通:
I thought it would be as easy as giving it your own CSS class with a background image, but that doesn't work:
.fw-button-edit {
background-image: url(edit.png);
}
有什么建议吗?
答
我也可以推荐:
.ui-button .ui-icon.your-own-custom-class {
background-image: url(your-path-to-normal-image-file.png);
width: your-icon-width;
height: your-icon-height;
}
.ui-button.ui-state-hover .ui-icon.your-own-custom-class {
background-image: url(your-path-to-highlighted-image-file.png);
width: your-icon-width;
height: your-icon-height;
}
然后输入JS代码:
jQuery('selector-to-your-button').button({
text: false,
icons: {
primary: "you-own-cusom-class" // Custom icon
}});
它对我有用,希望对你也有用!
It worked for me and hope it works for you too!