-2

我想知道,因为我不擅长 JavaScript 或 jQuery,如何淡化这个背景:

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

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

我不知道该怎么做。我自己一直在研究并尝试这样做,但过去三天没有成功。

任何帮助是极大的赞赏。

如果你需要代码,这里是:

索引.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>

样式.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; }
4

1 回答 1

1

添加这个

jQuery(document).ready(function() {

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

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

});

这仅适用于第一个图像淡入淡出效果。如果您想为不同的图像使用这种效果,您可能想尝试这个插件,我相信您会从中获得很酷的输出。

于 2013-07-26T16:58:30.037 回答