简体   繁体   English

Extjs - 如何在面板上的固定 position 处添加工具提示

[英]Extjs - How to add a tooltip at a fixed position on panel

I am trying to show a menu inside a tooltip on multiple panel items.我正在尝试在多个面板项的工具提示中显示菜单。 So on hover of those item-panels I want to show my menu button which will be displayed with the means of tooltip.因此,在这些项目面板的 hover 上,我想显示我的菜单按钮,该按钮将通过工具提示的方式显示。 I was able to do this much, but I am unable to set the tooltip location on top right corner of my panels items, as the tooltip is always displayed wherever I hover the mouse pointer.我能够做到这一点,但我无法在我的面板项目的右上角设置工具提示位置,因为工具提示总是显示在我 hover 鼠标指针的任何位置。 Also I tried using the anchor config, but it just attaches the tooltip to the parent panel.我也尝试使用锚配置,但它只是将工具提示附加到父面板。 Is there any configuration to set the position of tooltip or any other approach to achieve this use case.是否有任何配置可以设置工具提示的 position 或任何其他方法来实现此用例。

Here is my fiddle .这是我的小提琴

I was able to fix the position of tooltip to the top-right corner of panel by using the configs anchor: true and defaultAlign: 't100-r30'通过使用配置anchor: truedefaultAlign: 't100-r30'

Below is the updated fiddle code:以下是更新的小提琴代码:

var someButton = Ext.create({
    xtype: 'button',
    text: 'Some button'
});

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.create({
            id: 'parentPanel',
            height: 300,
            xtype: 'panel',
            title: 'parentPanel',
            items: [{
                html: "<span style='font-size:20px;'>Hover mouse on this green panel</span>",
                bodyStyle: "background: lightgreen;",
                xtype: 'panel',
                height: "50%",
                width: "70%",
                padding: "5 5",
                cls: 'overlayMenuCls'
            }, {
                html: "<span style='font-size:20px;'>Hover mouse on this blue panel</span>",
                bodyStyle: "background: lightblue;",
                xtype: 'panel',
                height: "50%",
                width: "70%",
                padding: "5 5",
                cls: 'overlayMenuCls'
            }],
            listeners: {
                boxready: {
                    fn: 'onPanelBeforeRender',
                    scope: this
                }
            },
            layout: "vbox",
            renderTo: Ext.getBody()
        });
    },

    onPanelBeforeRender: function (view) {
        var me = this;
        console.log(view);
        var tip = Ext.create('Ext.tip.ToolTip', {
            target: view.el,
            delegate: '.overlayMenuCls',
            //             trackMouse: true,
            anchor: true,
            dismissDelay: 0,
            defaultAlign: 't100-r30',
            items: [{
                xtype: 'button',
                text: 'menu',
                cls: "overlayMenuCls",
                menu: {
                    items: [{
                        text: 1
                    }, someButton]
                },
                listeners: {
                    mouseover: function () {
                        tip.isItemOver = true;
                    },
                    mouseout: function () {
                        tip.isItemOver = false;
                    }
                }
            }],
            listeners: {
                beforeshow: function (tip) {
                    var button = tip.items.items[0];
                    var menu = button.menu;
                    console.log(tip.items.items[0]);
                },
                beforehide: function (tip) {
                    if (tip.isItemOver) {
                        return false;
                    }
                }
            }
        });
    }
});

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

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