【发布时间】:2013-05-15 15:08:15
【问题描述】:
我正在尝试将标题的背景淡入white,但是当我尝试使用一些 jQuery 动画背景颜色的淡出时,它就不起作用了。
jQuery
var windw = this;
$.fn.followTo = function ( pos ) {
var $this = this,
$window = $(windw);
$window.scroll(function(e){
if ($window.scrollTop() > pos) {
$this.animate({'backgroundColor':'rgba(255,255,255,1)'},400);
console.log($this.css('backgroundColor'));
console.log(pos);
} else if ($window.scrollTop() == 0) {
$this.animate({'backgroundColor':'rgba(255,255,255,0)'});
console.log($this.css('backgroundColor'));
console.log(pos + ' at the top');
} else {
$this.animate({'backgroundColor':'rgba(255,255,255,0)'});
console.log($this.css('backgroundColor'));
}
});
};
$('.home-header-main').followTo(86);
感谢您的帮助
【问题讨论】:
-
看起来你真的想为不透明度而不是背景颜色设置动画?
-
@jlbruno 我会失去我的内容的不透明度。
-
如果您包含 jQuery UI,它就可以工作。如果您在项目中确实引用了 jQuerUI,请确保包含了效果模块。见jsfiddle.net/tJVQt/3
-
jQuery 不支持这样的动画 rgba 颜色。
标签: jquery jquery-animate