如何制作仅自定义图标的 jQuery UI 按钮小部件?

发布于 2024-12-21 17:45:53 字数 560 浏览 5 评论 0原文

我正在尝试用 jQuery UI 来替代其他 RIA 技术,但我想制作一个仅图标按钮。我知道我们可以使用默认的主题滚轮图标来做到这一点,但我想使用我自己的图标。

我已成功创建(请参阅此处)带有自定义图标和文本的自定义按钮,但如果我删除文本,它就会变得不成比例且丑陋。

我尝试将 包装在

中,然后在其上调用 .button() 但它得到太大;我真正想要的是有一个图标按钮,就像主题附带的图标按钮一样,但使用我自己的图标。

希望我已经说得清楚易懂,

FA

(想想 extJS 仅图标按钮或 Adob​​e Flex(你为什么抛弃我)仅图标按钮)

I'm trying my hand at jQuery UI as a replacement for other RIA techniques but I wanted to make an icon-only button. I'm aware that we can do it using the default theme-roller icons but I want to use my own icons.

I've successfully created (see here) a custom button with a custom icon and text, but if I remove the text then it becomes disproportionate and ugly.

I've tried just wrapping an <img> in a <div> and then calling .button() on it but it gets too large; what I really wanted is to have an icon-button like the ones that ship with the theme but using my own icons instead.

Hoping I've made myself clear and understandable,

FA

(think extJS icon-only buttons or Adobe Flex (why have you forsaken me) icon-only buttons)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自在安然 2024-12-28 17:45:53

这似乎对我有用(改编自演示此处以及您提到的答案)。看起来关键是将 text 选项设置为 false

JavaScript:

$('#button').button({
    text: false, /* Don't include text on the button */
    icons: {
        primary: 'ui-icon-custom'
    }
});

CSS:

#button > span.ui-icon-custom {
    background-image: url(http://placekitten.com/25/25)
}

示例: http://jsfiddle.net/ReKbf/

(对糟糕的占位符图像表示歉意)

This seems to work for me (adapted from the demo here and the answer you mentioned). It looks like the key is setting the text option to false:

JavaScript:

$('#button').button({
    text: false, /* Don't include text on the button */
    icons: {
        primary: 'ui-icon-custom'
    }
});

CSS:

#button > span.ui-icon-custom {
    background-image: url(http://placekitten.com/25/25)
}

Example: http://jsfiddle.net/ReKbf/

(Apologies for the terrible placeholder image)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文