我正在使用以下 jquery 弹跳效果:
(function($){
/* The plugin extends the jQuery Core with four methods */
/* Converting an element into a bounce box: */
$.fn.bounceBox = function(){
/*
Applying some CSS rules that center the
element in the middle of the page and
move it above the view area of the browser.
*/
this.css({
top : -this.outerHeight(),
marginLeft : -this.outerWidth()/2,
position : 'fixed',
left : '50%'
});
return this;
}
/* The boxShow method */
$.fn.bounceBoxShow = function(){
/* Starting a downward animation */
this.stop().animate({top:0},{easing:'easeOutBounce'});
this.data('bounceShown',true);
return this;
}
/* The boxHide method */
$.fn.bounceBoxHide = function(){
/* Starting an upward animation */
this.stop().animate({top:-this.outerHeight()});
this.data('bounceShown',false);
return this;
}
/* And the boxToggle method */
$.fn.bounceBoxToggle = function(){
/*
Show or hide the bounceBox depending
on the 'bounceShown' data variable
*/
if(this.data('bounceShown'))
this.bounceBoxHide();
else
this.bounceBoxShow();
return this;
}
})(jQuery);
在以下动态加载的动态 div 上:
<div id="growl">
<span id="growl-title" class="growl-title"></span>
<span id="growl-content" class="growl-content"></span>
</div>
目前效果如下:用户点击按钮然后在服务器端完成后执行回调javascript以显示div,效果如下:
$('#growl').bounceBoxToggle();
但我有一个案例,从服务器端我根据一个属性显示这个 div(div 可能由于 ajax 调用而附加到 dom),如下所示:
<c:if test="#{showGrowl==true}">
<div id="growl">
<span id="growl-title" class="growl-title"></span>
<span id="growl-content" class="growl-content"></span>
</div>
</c:if>
,我希望在这种情况下,当显示 div 时自动应用反弹效果,请告知如何做到这一点。