jquery更改背景颜色用户滚动 [英] jquery change background color user scroll
本文介绍了jquery更改背景颜色用户滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jquery 是否有可能当用户向下滚动页面时,背景会从 50% 白色变为 90% 白色或其他动画?
Is it possible with jquery that when a user scrolls down the page that the background animate from 50% white to 90% white or someting?
所以首先是颜色 rgba(255,255,255,.5)
,当用户滚动到颜色下方 210px 时,变成 rgba(255,255,255,.9)
.>
So first it is the color rgba(255,255,255,.5)
and when a user scroll 210px below the color become rgba(255,255,255,.9)
.
推荐答案
here you go(这将在滚动超过 210 像素时将页面颜色更改为蓝色,如果返回将恢复为红色):
here you go (this will change the page color to blue when you scroll more than 210px, and will revert back to red if you go back up):
$(document).ready(function(){
var scroll_pos = 0;
$(document).scroll(function() {
scroll_pos = $(this).scrollTop();
if(scroll_pos > 210) {
$("body").css('background-color', 'blue');
} else {
$("body").css('background-color', 'red');
}
});
});
这篇关于jquery更改背景颜色用户滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文