开发者

Can I set a Custom Icon for a jQueryUI Button

开发者 https://www.devze.com 2022-12-30 12:24 出处:网络
Is it possible to create a jQueryUI Button with a custom icon, ie: an icon that is not part of the sprite icons that are provided with jQueryUI???

Is it possible to create a jQueryUI Button with a custom icon, ie: an icon that is not part of the sprite icons that are provided with jQueryUI???

I am using the ButtonSet functionality for a group of 3 checkboxes but need a more styli开发者_如何转开发sed icon than what is provided out of the box...


Worked it out with a CSS hack.

Setup the button as per normal and give the primary icon the "Error" class defined below

.Error
{
    background-image: url('Images/Icons/16/Error.png') !important;
}

The !important overrides the ui-icon definition for background-image.


I took this approach for one of my buttons and I discovered some interesting things:

  1. I didn't need to use the "!important" override
  2. I needed to set background-position for my button (otherwise I think the background was being displayed well outside the button)
  3. It looks like you can also put anything you like in the jQueryUI primary icon name - it just needs something as a placeholder.

For my uses I ended up with:

Javascript:

jQuery(function() {
    jQuery('#share-button').button({
        icons: { primary: "icons/share" }
    });

});

CSS:

#share-button > span.ui-icon {
    background-image: url(icons/share.png);
    background-position:0px 3px;}

HTML:

<button id='share-button'>Share</button>
0

精彩评论

暂无评论...
验证码 换一张
取 消