简体   繁体   English

Ext GWT在鼠标悬停时更改ContentPanel背景颜色

[英]Ext GWT change ContentPanel background color on mouseover

In my page I have a Gxt ContentPanel with a white background. 在我的页面中,我有一个带有白色背景的Gxt ContentPanel。 However, when the user mouses over the Header of the ContentPanel, I would like the background to change colors. 但是,当用户将鼠标悬停在ContentPanel的页眉上时,我希望背景更改颜色。

I tried achieving this by using the protected addStyleOnOver method of Gxt Component, but it doesn't have any effect. 我尝试使用Gxt Component的受保护的addStyleOnOver方法来实现此目的,但是它没有任何效果。 Is there anything else I need to do to use that methods (I'm already sinking the ONMOUSEOVER and ONMOUSEOUT events), or a better way to change the background? 使用该方法是否需要做其他事情(我已经沉没了ONMOUSEOVER和ONMOUSEOUT事件),或者是更改背景的更好方法?

you can do this using below code its working 你可以使用下面的代码来做到这一点

    ContentPanel contentPanel = new ContentPanel();
    contentPanel.setStyleName("background");

and write below code in your css 并在css中编写以下代码

   .background:hover .x-panel-body {background-color: red !important;}

i'm not sure if this works, but you can test it... 我不确定这是否有效,但是您可以对其进行测试...

final ContentPanel test = new ContentPanel();
test.getHeader().addListener(Events.OnMouseOver, new Listener<BaseEvent>() {
    @Override
    public void handleEvent(BaseEvent be) {
        test.getHeader().setStyleName("your_new_style");
        // or test.setStyleName("your_new_style");
    }
});

You could simply add a style to the header, then add some css to change the color. 您可以简单地在标题中添加样式,然后添加一些CSS以更改颜色。

test.getHeader().addStyleName("my_style")

# css
my_style:hover { background-color: yellow; }

This is a bit trickier if you want to change the bg of the whole ContentPanel during onMouseOver of the header, in which case, add the mouse over event to the header where handle event adds style to the content panel (or content panel body depending on what you want), then add the appropriate styles to you css. 如果要在标题的onMouseOver期间更改整个ContentPanel的bg,则有点棘手,在这种情况下,将鼠标悬停事件添加到标题,其中handle事件将样式添加到内容面板(或内容面板主体,具体取决于您想要的),然后向您的CSS添加适当的样式。

# css
my_style { background-color: yellow; }

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

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