简体   繁体   中英

How to permanently show a p:tooltip?

I'm trying to permanently show the p:tooltip in a PrimeFaces project I'm working on.
This is my current code:

<p:graphicImage id="testImg" name="/img/testImg.jpg" onclick="PF('info').show();" style="cursor: pointer"/> 
<p:tooltip for="testImg" value="further information" position="right" />
<p:dialog widgetVar="info" modal="true" closeOnEscape="true" >
    <h:outputText value="bla bla bla"/>
</p:dialog>

I tried this:

<p:tooltip for="testImg" value="further information" position="right" showEevent="permanent"/>

but it didn't work.

Is there any way to control the tooltip and have it permanently visible without having to mouse over or focus the controlling element?

As you have noticed, there is no show event called permanent. What you could do is controlling the tooltip with JavaScript using a widget variable. You can assign one for the tooltip using the widgetVar attribute. The tooltip widget has several functions, one of them is show() (to show the tooltip).
When the tooltip is shown there is a delay of 150 msec, so set that to 0 to immediately show the tooltip. To prevent the tooltip from being hidden, set the hideEvent to some non existing event (like none ).

Putting it all together:

<h:panelGrid columns="3">
  <h:outputText value="Permanent" />
  <p:inputText id="permanent"
               title="Permanent tooltip" />
  <p:tooltip id="permanentTip"
             for="permanent"
             widgetVar="permanentTip"
             showDelay="0"
             hideEvent="none"/>
</h:panelGrid>

<script>
  $(function(){ 
    PF('permanentTip').show();
  });
</script>

See also:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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