2013-07-26 73 views
-2

我想知道一个背景,因为我不擅长JavaScript或jQuery的,怎么我消失的这一个背景:衰落与jQuery

html { 
    background-image:url(image.png); 
} 

到不同的背景图像不褪色整个文档,但每2秒只有背景?

我不知道如何做到这一点。我自己一直在研究和尝试这样做,但过去三天没有成功。

任何帮助,非常感谢。

如果您需要的代码,那就是:

的index.html

<!DOCTYPE html> 
      <html> 

      <head> 
       <title>Buddies Server Home</title> 
       <link href="css/styles.css" rel="stylesheet" /> 
       <script src="http://code.jquery.com/jquery-latest.js"></script> 
      </head> 

      <body> 
       <div class="body"> 
        <div class="nav"> 
         <div class="header"> 
          <img src="images/Logo.png" /> 
         </div> 
         <div class="right-side"> 
          <img src="images/home.png" /> 
         </div> 
         <div class="nav-buttons"> 
          <a href="http://192.168.2.202/server"><img src="images/buttons/servers.png" /></a> 
          <a href="about.php"><img src="images/buttons/about.png" /></a> 
          <a href="/forum/index.php"><img src="images/buttons/forums.png" /></a> 
         </div> 
         <div class="notif_container"> 
          <div class="notif"><p id="notif">NOTIFICATION: Buddies Network is under maintenance. Thank you for your patience.</p></div> 
         </div> 
        </div> 
       </div> 

       <div class="content"> 
        <div class="post"> 
         <table id="post"> 
          <tr> 
           <td id="title"><h2>Blog Entry 1</h2></td> 
          </tr> 
          <tr> 
           <td><h5 id="author">DirectX3DNerd, 7/23/13</b></td> 
          </tr> 
          <tr> 
           <td id="body"><p>Post Body</p></td> 
          </tr> 
         </table> 

         <table id="post"> 
          <tr> 
           <td id="title"><h2>Blog Entry 2</h2></td> 
          </tr> 
          <tr> 
           <td><h5 id="author">DirectX3DNerd, 7/1337/13</b></td> 
          </tr> 
          <tr> 
           <td id="body"><p>Post Body - Jacob was Here</p></td> 
          </tr> 
         </table> 
        </div> 

        <div class="side_bar"> 
         <table id="side_bar"> 
          <tr> 
           <td><h2>Welcome!</h2></td> 
          </tr> 
          <tr> 
           <td><p>Welcome to Buddies Netowrk! Home of the Minecraft, Ace of Spades, and Team Fortress 2 server! If you want to play on one of the servers, click <a href="servers.php">here</a></p></td> 
          </tr> 
         </table> 
        </div> 
       </div> 
       <div class="footer"> 
        <b>&copy; Buddies Network, 2012-2014.</b> 
       </div> 
      </body> 
      <script> 
       var image1 = 'images/bg.png'; 
       var image2 = 'images/bg2.png'; 

      function fade() { 
       $(html).css('background-image', image1); 
       $(html).css('background-image', image1); 
      } 
      </script> 

      </html> 

styles.css的

/* Document Properties */ 
      html { 
       background: url('../images/bg.png') no-repeat center center fixed; 
       -webkit-background-size: cover; 
       -moz-background-size: cover; 
       -o-background-size: cover; 
       background-size: cover; 
      } 

      /* Server List Properties */ 
      .server_list { 
       width:500px; 
       height:400px; 
       margin: auto; 
      } 
      .server_list li { 
       width:60%; 
       margin:auto; 
      } 

      /* Font Properties */ 
      b{ 
       font-family:"Times New Roman", Times, serif; 
      } 
      h1{ 
       font-family:"Times New Roman", Times, serif; 
      } 
      p{ 
       font-family:"Times New Roman", Times, serif; 
      } 

      /* Page Template */ 

      /* Navigation Bar*/ 
      .header { 
       position:relative; 

       left:-1px; 
      } 

      .right-side { 
       position:absolute; 
       left:850px; 
       top:1px; 
      } 
      .notif { 
       background-color:#00FF15; 

       position:relative; 
       top:4px; 
      } 

      #notif { 
       color:#000000; 

       font-family:"Lucida Console", Monaco, monospace; 
       /*font-size:79%;*/ 

       width:800px; 
       height:35px; 

       margin:auto; 

       position:relative; 

       top:10px; 

       overflow:auto; 
       word-wrap:break-word; 
      } 

      .nav { 
       background-color:#FFFFFF; 

       min-height:79px; 
       min-width:100%; 

       position:fixed; 

       top:0px; 
       left:0px; 
       right:0px; 

      } 

      /* Footer */ 
      .footer { 
       background-color:#eee; 

       min-width:100%; 
       height:20px; 

       position:fixed; 

       left:0px; 
       bottom:0px; 
      } 

      /* Blog Post styles */ 
      .post { 
       background-image:url('../images/trans_bg.png'); 

       color:white; 
       position:absolute; 
       z-index:-1; 
       top:200px; 
       left:350px; 

       width:550px; 
       height:750px; 
      } 

      #post { 
       position:relative; 
       left:0px; 

       padding:0; 
       margin:0; 
      } 

      #title { 
       position:relative; 

       top:-10px; 
       left:0px; 
      } 

      #author { 
       position:relative; 
       top:-50px; 
       left:0px; 
      } 

      #body { 
       position:relative; 
       top:-80px; 
       left:0px; 
      } 

      /* Misc */ 
      .side_bar { 
       background-image:url('../images/trans_bg.png'); 
       color:white; 

       position:fixed; 
       top:190px; 
       left:5px; 

       width:250px; 

       word-wrap:break-word; 
       overflow:hidden; 
      } 

      /* link Properties */ 
      a:link { color:white; } 
      a:visited { color:white; } 
      a:hover { color:white; } 
      a:active { color:white; } 
+0

你不能。淡化背景图像的唯一方法是淡化元素本身。 –

回答

1

添加此

jQuery(document).ready(function() { 

$("html").css({ 
'background-image': '' 
}); 

$("html").animate({ background:'url(image.png)'},350); 

}); 

这只是为第一个图像淡入淡出效果。如果你想为不同的图像效果,你可以试试这个plug-in我相信你会从它得到很酷的输出。

+0

它支持多个图像吗? – Djmann1013

+0

我刚刚添加了一个插件,将做的伎俩@ Djmann1013 –

+0

插件是惊人的!谢谢! – Djmann1013