jQuery的变化背景颜色用户滚动 [英] jquery change background color user scroll

查看:240
本文介绍了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).

推荐答案

在这里你去(这将改变页面的颜色为蓝色,当你滚动比210px多了,如果你去备份将恢复到红色):

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆