jQuery on window scroll animate background image position

前端 未结 6 2298
小鲜肉
小鲜肉 2020-12-12 18:26

I am trying to achieve a scrolling effect using jQuery. I have a background div set to 100% browser window size with overflow hidden. This has a large background image that

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 19:13

    Look here to see an example of how far the user has scrolled on the page. See the $(this).scrollTop()?

    Rather than referencing $(this), try using the background div. Then use a .scroll function to determine how much to move the background.

    Your code should look something sort of like this:

    $("html").scroll(function{
      var move["bottom"] = $("bg_div").scrollTop();
      $("bg_div").animate({bottom: move}, 500);
    });
    

提交回复
热议问题