我正在使用Initializr和Bootstrap3来开发一个网站。我编写了一个当用户滚动超过一定限制时显示的面板。Html面板代码为:
<div id="navigation-panel">
<div class="container-fluid">
<div class="row">
<div class="col-xs-10"></div>
<div class="col-xs-2 pull-right">
<i class="fa fa-chevron-circle-up yellow"></i>
</div>
</div>
</div>
</div>而CSS代码是:
#navigation-panel{
position: fixed;
bottom: 0;
width: 100%;
height: 6%;
background-color: #545454;
z-index:15;
border-top: 3px solid;
animation-duration: 5s;
animation-name: changeBorderBottomColor;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#navigation-panel i{
font-size: 1.6em;
margin-top: 1%;
}
我使用了以下代码片段:
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
return el.apply(this, arguments);
};
});
})(jQuery);并以这种方式附加事件处理程序:
$('#navigation-panel').on( "show", function() {
$('#navigation-panel').removeClass();
var animationName = 'animated bounceIn';
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
$('#navigation-panel').addClass(animationName).one(animationEnd,function(){
$(this).removeClass(animationName);
});
});
$('#navigation-panel').on( "hide", function() {
$('#navigation-panel').removeClass();
var animationName = 'animated bounceOut';
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
$('#navigation-panel').addClass(animationName).one(animationEnd,function(){
$(this).removeClass(animationName);
});
});隐藏和显示control #导航面板javascript代码如下:
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
console.log(scroll);
if(scroll >= (h - 100))
{
$('#navigation-panel').show();
}
else
{
$('#navigation-panel').hide();
}
});其中h变量是视口高度。
面板将正常显示和消失,但不显示任何动画。我哪里错了?
非常感谢!
发布于 2015-10-22 23:32:04
尝试在同一行中使用removeClass:$('#navigation-panel').removeClass().addClass(......或者尝试不使用变量。
https://stackoverflow.com/questions/33284184
复制相似问题