代码之家  ›  专栏  ›  技术社区  ›  Jason

后台切换页面加载

  •  1
  • Jason  · 技术社区  · 14 年前

    我已经看到了很多不同的基于链接类的背景切换,但是我只想在任何页面加载(没有cookies)和不依赖链接的简单背景切换。

    有简单的方法吗?jquery?

    2 回复  |  直到 13 年前
        1
  •  3
  •   Mouhannad    14 年前

    正在寻找javascript timers ?

    setInterval("switchBackground()", 1000);
    
    function switchBackground( )
    {
       $("body").css("backgroundImage", "xxx");
    }
    

    希望能帮上忙!

    编辑:

    $(document).ready(function() {
       //This will be random from bg1.jpg to bg10.jpg
       $("body").css("backgroundImage", "/images/bg"+GenerateNumber(10)+".jpg");
    
       //1 to max
       function GenerateNumber(max) {
          return Math.floor(Math.random()*max) + 1;
       }
    });
    
        2
  •  3
  •   Charlie Stanard    12 年前

    Mouhannad提供的随机背景图像的代码对我不起作用,我必须做一些小的编辑才能使其正常工作:

    $(document).ready(function() {
       //This will be random from bg1.jpg to bg10.jpg
       $("body").css("background-image", "url(/images/bg"+GenerateNumber(10)+".jpg)");
    
       //1 to max
       function GenerateNumber(max) {
          return Math.floor(Math.random()*max) + 1;
       }
    });