0

我有一个文件夹,其中包含 400 张以连续数字命名的图像(1、2、3 ..)(将视频转换为图像)。我想通过滚动位置更改文件夹中的这些图像来增加或更改窗口背景。我是新手有什么建议吗?

4

2 回答 2

0

使用滚动事件

jQuery(window).on("scroll",function() {
   if( some condition is true ) { //do some kind of check to see if you are
                                  //far enough down to require a change
      var lastbg = jQuery("body").css("background-image");
      //do some manipulation to get the last number
      jQuery("body").css({backgroundImage:"url(urltonewimage)"});
   }
});
于 2013-07-26T11:08:24.213 回答
0

您可以使用scrollTop()计算它滚动了多远,然后相应地更改图像。

jQuery(window).on("scroll",function() {
   var n = $(window).scrollTop(); // Set scroll number
   if (n <= 0) { var n = 0; } // Check that value isn't smaller than 0
   jQuery("body").css({backgroundImage:"url(imagename"+n+"});
});

这可能会做到这一点,但我还没有测试过。

于 2013-07-26T11:14:37.817 回答