最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - extjs4 replace button with an image issue - Stack Overflow

programmeradmin7浏览0评论

So I am trying replacing an extjs button with an image and have it display some tooltip. The thing is I just want to display the image and I dont want the background of the extjs button. Here is my code below. To get an idea of what I am talking about , here is the js fiddle: /

CSS:

.question {
    background-image: url(../www/css/slate/btn/question.png) !important;
    background-repeat: no-repeat;
}

Javascript:

{
    xtype: 'button',
    iconCls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pages<br> ",
    padding: '2 6 2 7',
    width: 20,
    height: 24
}

EDIT:I replaced the button with text and that shows only the image. But it does not dispaly the tooltip.

{
    xtype: 'text',
    cls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pagess ",
    height: 20,
    padding: '12 6 2 7'
}

So I am trying replacing an extjs button with an image and have it display some tooltip. The thing is I just want to display the image and I dont want the background of the extjs button. Here is my code below. To get an idea of what I am talking about , here is the js fiddle: http://jsfiddle/nCkZN/7/

CSS:

.question {
    background-image: url(../www/css/slate/btn/question.png) !important;
    background-repeat: no-repeat;
}

Javascript:

{
    xtype: 'button',
    iconCls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pages<br> ",
    padding: '2 6 2 7',
    width: 20,
    height: 24
}

EDIT:I replaced the button with text and that shows only the image. But it does not dispaly the tooltip.

{
    xtype: 'text',
    cls: 'question',
    tooltip: "<b>read-only</b>:Read-only users will have read only access to all pagess ",
    height: 20,
    padding: '12 6 2 7'
}
Share Improve this question edited May 13, 2013 at 19:10 Darin Kolev 3,40913 gold badges33 silver badges47 bronze badges asked Dec 12, 2012 at 16:41 MichealMicheal 2,33210 gold badges52 silver badges96 bronze badges 2
  • So it's not supposed to look like a button? Why make it a button? – Ruan Mendes Commented Dec 12, 2012 at 19:09
  • Ok I updated it to just text..but that doesnt give me the tool tip anymore. jsfiddle/nCkZN/13 – Micheal Commented Dec 12, 2012 at 19:14
Add a ment  | 

2 Answers 2

Reset to default 6

You can modify the look of the button through CSS http://jsfiddle/nCkZN/10/

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'button',
        cls: 'my-btn', // Add this so you can style the button
        iconCls:'questionIcon',
        tooltip:"<b>read-only</b>:Read-only users will have read only access to all pages<br> ",
        padding: '2 6 2 7'                    
    }]
});​

CSS

.questionIcon {
  background-image:url(http://www.myimage./pic.png) !important;
  background-repeat: no-repeat;            
}

.my-btn {
  border-radius: 0;
  background-image: none;
  border: 0;
}

you can alternatively use a regular Ext.Img and add a tooltip to it. Seems cleaner than using a button when you don't want a button. http://jsfiddle/nCkZN/15/

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'image',
        src:'http://www.southampton.ac.uk/isolutions/puting/elearn/blackboard/small_pen.gif',
        padding: '2 6 2 7',
        listeners: {
            render: function(cmp) {
                Ext.create('Ext.tip.ToolTip', {
                    target: cmp.el,
                    html: "<b>read-only</b>:Read-only users will have read only access to all pages<br> "
                });
            }
        }
    }]
});​

What you really seem to be after is a way to add a tooltip to any ponent. Here's a plugin to do it.

Ext.define('Ext.ux.Tooltip', {
    extend: 'Ext.AbstractPlugin',
    alias: 'plugin.ux-tooltip',

    /**
     * @cfg html The text to put into the tooltip
     */
    init: function(cmp) {
        var me = this;
        cmp.on('render', function() {
            Ext.create('Ext.tip.ToolTip', {
                target: cmp.el,
                html: me.html
            });        
        });
    }
});

Now it's easy to add a tooltip to any ponent http://jsfiddle/nCkZN/17/

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'image',
        src:'http://www.southampton.ac.uk/isolutions/puting/elearn/blackboard/small_pen.gif',
        padding: '2 6 2 7',
        plugins: {
            ptype: 'ux-tooltip', 
            html: '<b>read-only</b>:Read-only users will have read only access to all pages<br> '
        }
    }]
});

background-image: url(../www/css/slate/btn/question.png) !important;

First problem there is you need single quotes around your url.

In your jsfiddle, changed to this:

.question{
  background-image:url('http://www.southampton.ac.uk/isolutions/puting/elearn/blackboard/small_pen.gif');
  background-repeat: no-repeat;
}​

Second, you probably don't want to specify an iconCls if you don't actually have any text, you're better off just passing a cls. I think the iconCls is if you pass an icon in as a config.

发布评论

评论列表(0)

  1. 暂无评论