根据滚动更改导航栏上的RGBA背景颜色 [英] Changing rgba background color on navbar based on scroll
本文介绍了根据滚动更改导航栏上的RGBA背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面顶部有一个bootstrap固定导航栏.我想根据页面上的滚动位置将背景颜色的不透明度从0逐渐逐渐提高到0.75.如何使用jquery做到这一点?
I've got a bootsrap fixed navbar at the top of my page. I'd like to gradually and smoothly increase the background-color opacity from 0 up to 0.75 based on the scroll position on the page. How can I do this using jquery?
滚动之前
.navbar-inverse {
background: rgba(53,145,204,0);
}
滚动后〜500px或更好,但仍为当前窗口大小的100%
after scroll ~500px or better yet 100% of current window size
.navbar-inverse {
background: rgba(53,145,204,0.75);
}
推荐答案
使用它来达到类似的效果:
Used this to achieve a similar effect:
$(function() {
//caches a jQuery object containing the header element
var header = $(".fade-transparent");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 200) {
header.removeClass('fade-transparent').addClass("fade-background");
} else {
header.removeClass("fade-background").addClass('fade-transparent');
}
});
});
.fade-background {
background-color: #3591cc;
background-color: rgba(53,145,204,0.75);
-webkit-transition: background-color 3s;
transition: background-color 3s;
}
.fade-transparent {
background-color: transparent;
-webkit-transition: background-color 1s;
transition: background-color 1s;
}
这篇关于根据滚动更改导航栏上的RGBA背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文