Changing background color based on page position

前端 未结 2 1483
渐次进展
渐次进展 2021-01-28 21:01

I juste want to change the background color based on the scroll. Red to blue for exemple...

This code works but how can I change the grey to a color ?

ht

2条回答
  •  走了就别回头了
    2021-01-28 21:06

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

提交回复
热议问题