【问题标题】:Apply animation effect on button click - JSF在按钮单击时应用动画效果 - JSF
【发布时间】:2016-04-27 08:52:22
【问题描述】:

我为 jsf 组件找到了这些动画:http://www.animatejsf.org/

我尝试通过命令链接单击将其应用于<h:form>,如图所示

<h:form id="leftMenu">
Slide
</h:form>

<p:commandLink>
    <p:outputLabel> click here
        <aj:animate target="leftMenu" type="slideInLeft"/>
    </p:outputLabel>
</p:commandLink>

但是点击命令链接时动画不可见。相反,它最初只是在网页加载时制作动画。我想在点击&lt;p:commandButton&gt;&lt;p:commandLink&gt; 时应用此动画。

有谁知道我怎样才能做到这一点?任何帮助表示赞赏。

【问题讨论】:

    标签: jsf animation jsf-2


    【解决方案1】:

    您是否已经尝试过:

    <p:effect type="clip" event="click" />
    

    这里是一个例子:

    <h3 style="margin-top:0">Catalog</h3>
    <h:panelGrid columns="4" cellpadding="5">
        <p:panel id="blind" header="Blind">
            <h:outputText value="click" />
            <p:effect type="blind" event="click">
                <f:param name="direction" value="'horizontal'" />
            </p:effect>
        </p:panel>
    
        <p:panel id="clip" header="Clip">
            <h:outputText value="click" />
            <p:effect type="clip" event="click" />
        </p:panel>
    
        <p:panel id="drop" header="Drop">
            <h:outputText value="click" />
            <p:effect type="drop" event="click" />
        </p:panel>
    
        <p:panel id="explode" header="Explode">
            <h:outputText value="click" />
            <p:effect type="explode" event="click" />
        </p:panel>
    
        <p:panel id="fold" header="Fold">
            <h:outputText value="doubleclick" />
            <p:effect type="fold" event="dblclick" />
        </p:panel>
    
        <p:panel id="puff" header="Puff">
            <h:outputText value="doubleclick" />
            <p:effect type="puff" event="dblclick" />
        </p:panel>
    
        <p:panel id="slide" header="Slide">
            <h:outputText value="doubleclick" />
            <p:effect type="slide" event="dblclick" />
        </p:panel>
    
        <p:panel id="scale" header="Scale">
            <h:outputText value="doubleclick" />
            <p:effect type="scale" event="dblclick">
                <f:param name="percent" value="90" />
            </p:effect>
        </p:panel>
    
        <p:panel id="bounce" header="Bounce">
            <h:outputText value="click" />
            <p:effect type="bounce" event="click" />
        </p:panel>
    
        <p:panel id="pulsate" header="Pulsate">
            <h:outputText value="click" />
            <p:effect type="pulsate" event="click" />
        </p:panel>
    
        <p:panel id="shake" header="Shake">
            <h:outputText value="click" />
            <p:effect type="shake" event="click" />
        </p:panel>
    
        <p:panel id="size" header="Size">
            <h:outputText value="click" />
            <p:effect type="size" event="click">
                <f:param name="to" value="{width: 200,height: 60}" />
            </p:effect>
        </p:panel>
    </h:panelGrid>
    
    <h3>Target</h3>
    <p:commandButton type="button" value="Show" style="display:block" icon="ui-icon-image">
        <p:effect type="puff" event="click" for="img">
            <f:param name="mode" value="'show'" />
        </p:effect>
    </p:commandButton>
    <p:graphicImage id="img" name="demo/images/nature/nature1.jpg" style="display:none"/>
    
    <h:form>
        <h3>On Load</h3>
        <p:messages id="messages" closable="true">
            <p:effect type="pulsate" event="load" delay="500" />
        </p:messages>
    
        <p:panel id="panel" header="Message Effects" toggleable="true">
            <h:panelGrid columns="2" cellpadding="5">
                <p:outputLabel for="text" value="Type:" />
                <p:inputText id="text" value="#{effectView.text}" required="true" />
    
                <h:outputText />
                <p:commandButton id="submit" value="Echo" actionListener="#{effectView.echo}" update="messages"/>
            </h:panelGrid>
        </p:panel>
    </h:form
    

    >

    package org.primefaces.showcase.view.misc;
    
    import javax.faces.application.FacesMessage;
    import javax.faces.bean.ManagedBean;
    import javax.faces.context.FacesContext;
    
    @ManagedBean
    public class EffectView {
    
        private String text;
    
        public String getText() {
            return text;
        }
    
        public void setText(String text) {
            this.text = text;
        }
    
        public void echo() {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You said:'" + text + "'"));
        }
    }
    

    http://www.primefaces.org/showcase/ui/misc/effect.xhtml

    使用 commandLink 对我来说效果很好。

    【讨论】:

    • 我不想在commandlink 上应用动画。我想使用commandlinkcommandbuttonform 上应用动画。两者是有区别的。您展示的示例将在按钮单击时应用动画。不在独立于button 的任何其他元素上
    猜你喜欢
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多