Java GwtQuery-fadeOut()后的empty()小部件
出于对将引导警报/通知库包装到GWT的失望,我决定使用GwtQuery制作一个:Java GwtQuery-fadeOut()后的empty()小部件,java,gwt,gwtquery,gquery,Java,Gwt,Gwtquery,Gquery,出于对将引导警报/通知库包装到GWT的失望,我决定使用GwtQuery制作一个: public static void showErrorNotification(String message){ List<Widget> allNotifications = $(".notification").widgets(); for (Widget w : allNotifications){ $(w).fadeIn(1000); $(w).
public static void showErrorNotification(String message){
List<Widget> allNotifications = $(".notification").widgets();
for (Widget w : allNotifications){
$(w).fadeIn(1000);
$(w).append("<div id=\"errorAlert\" class=\"rounded10 errorAlert\">" +
"<img alt=\"\" src=\"public/images/exclamation.png\"> " +
"You must accept the terms and conditions to finish your registration." +
"</div>");
$(w).fadeOut(5000);
//$(w).empty();
}
}
公共静态无效通知(字符串消息){
列出所有通知=$(“.notification”).widgets();
for(小部件w:allNotifications){
美元(w).fadeIn(1000);
$(w).追加(“)+
" " +
“您必须接受条款和条件才能完成注册。”+
"");
$(w).衰减(5000);
//$(w).empty();
}
}
此代码的问题在于,用户可能多次调用此方法,因此追加
的HTML将随时间累积。注释行中的类似清空会导致通知甚至不显示
什么样的解决方案可以使它在淡出后清空通知面板
更新:
当我提出:
$(w).在fadeIn()之前清空(
)
在第二次调用此方法时不会显示任何内容。当所有动画完成后,您必须对函数进行排队以删除错误警报
每次调用showErrorNotification
方法时,都应该停止队列,以避免在完成之前多次调用队列时出现问题
您必须在添加之前删除errorAlert
,以避免在上次通知被删除之前停止的情况下重复
$(w).stop(true, true);
$(w).find(".errorAlert").remove();
$(w).append("<div id=\"errorAlert\" class=\"rounded10 errorAlert\">" +
"<img alt=\"\" src=\"public/images/exclamation.png\"> " +
"You must accept the terms and conditions to finish your registration." +
"</div>");
$(w).fadeIn(1000);
$(w).fadeOut(5000);
$(w).queue(new Function(){
public void f() {
$(this).find(".errorAlert").remove();
}
});
$(w).停止(true,true);
$(w).find(“.errorAlert”).remove();
$(w).追加(“)+
" " +
“您必须接受条款和条件才能完成注册。”+
"");
美元(w).fadeIn(1000);
$(w).衰减(5000);
$(w).queue(新函数(){
公共空间f(){
$(this.find(“.errorAlert”).remove();
}
});