我試圖淡入到white
的標題的背景,但當我嘗試使用一些jQuery來爲背景顏色的淡入淡出設置動畫時,它不會工作。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);
幫助表示讚賞
它看起來像你真的想動畫不透明度,而不是背景色? – Jeff
@jlbruno我會失去我的內容的不透明度。 – ngplayground
它適用於包含jQuery UI的用戶。如果您在項目中引用jQuerUI,請確保包含了效果模塊。參見http://jsfiddle.net/tJVQt/3/ – Yeronimo