jquery change background color user scroll

后端 未结 6 1060
南方客
南方客 2020-11-29 02:27

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?

So first it is the color

6条回答
  •  旧时难觅i
    2020-11-29 02:36

    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');
                    }
                });
            });
    

提交回复
热议问题